{"id":87,"date":"2015-11-08T22:19:45","date_gmt":"2015-11-08T21:19:45","guid":{"rendered":"http:\/\/hentati.org\/?p=87"},"modified":"2020-12-06T20:49:08","modified_gmt":"2020-12-06T19:49:08","slug":"87","status":"publish","type":"post","link":"https:\/\/hentati.org\/index.php\/2015\/11\/08\/87\/","title":{"rendered":"Linux Commands Network Configuration and Troubleshooting"},"content":{"rendered":"<p><span style=\"color: #000000;\">Computers are connected in a network to exchange information or resources each other. Two or more computer connected through network media called\u00a0<strong>computer network<\/strong>. There are number of network devices or media are involved to form computer network. Computer loaded with\u00a0<strong>Linux Operating System<\/strong>\u00a0can also be a part of network whether it is small or large network by its\u00a0<strong>multitasking and multiuser<\/strong>\u00a0natures. Maintaining of system and network up and running is a task of\u00a0<strong>System \/ Network Administrator\u2019s<\/strong>\u00a0job. In this article we are going to review frequently used network configuration and troubleshoot commands in Linux.<\/span><\/p>\n<h2><span style=\"color: #000000;\"><strong>1-IFCONFIG<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">ifconfig\u00a0(interface configurator) command is use to initialize an interface, assign\u00a0IP Address\u00a0to interface and\u00a0enable\u00a0or\u00a0disable\u00a0interface on demand. With this command you can view\u00a0IP Address\u00a0and\u00a0Hardware\u00a0\/\u00a0MAC address\u00a0assign to interface and also\u00a0MTU\u00a0(Maximum transmission unit) size.<\/span><\/p>\n<pre><span style=\"color: #000000;\">#<strong> ifconfig <\/strong><\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">ifconfig\u00a0with interface (eth0) command only shows specific interface details like\u00a0IP Address,\u00a0MAC Address\u00a0etc. with\u00a0-a\u00a0options will display all available interface details if it is disable also.<\/span><\/p>\n<pre><span style=\"color: #000000;\">#<strong> ifconfig eth0<\/strong><\/span><\/pre>\n<p>&nbsp;<\/p>\n<h3><span style=\"color: #000000;\">Assigning IP Address and Gateway<\/span><\/h3>\n<p><span style=\"color: #000000;\">Assigning an\u00a0IP Address\u00a0and\u00a0Gateway\u00a0to interface on the fly. The setting will be removed in case of system reboot.<\/span><\/p>\n<pre><span style=\"color: #000000;\">#<strong> ifconfig eth0 192.168.50.5 netmask 255.255.255.0<\/strong><\/span><\/pre>\n<p><span style=\"color: #000000;\">Enable or Disable Specific Interface<\/span><\/p>\n<p><span style=\"color: #000000;\">To\u00a0enable\u00a0or\u00a0disable\u00a0specific Interface, we use example command as follows.<\/span><\/p>\n<h3><span style=\"color: #000000;\">Enable eth0<\/span><\/h3>\n<pre><span style=\"color: #000000;\"># <strong>ifup eth0<\/strong><\/span><\/pre>\n<h3><span style=\"color: #000000;\">Disable eth0<\/span><\/h3>\n<pre><span style=\"color: #000000;\"># <strong>ifdown eth0<\/strong><\/span><\/pre>\n<p>&nbsp;<\/p>\n<h3><span style=\"color: #000000;\">Setting MTU Size<\/span><\/h3>\n<p><span style=\"color: #000000;\">By default\u00a0MTU\u00a0size is\u00a01500. We can set required\u00a0MTU\u00a0size with below command. Replace\u00a0XXXX\u00a0with size.<\/span><\/p>\n<pre><span style=\"color: #000000;\">#<strong> ifconfig eth0 mtu XXXX<\/strong><\/span><\/pre>\n<p>&nbsp;<\/p>\n<h3><span style=\"color: #000000;\">Set Interface in Promiscuous mode<\/span><\/h3>\n<p><span style=\"color: #000000;\">Network interface\u00a0only received packets belongs to that particular\u00a0NIC. If you put interface in\u00a0promiscuousmode it will received all the packets. This is very useful to capture packets and analyze later. For this you may require superuser access.<\/span><\/p>\n<pre><span style=\"color: #000000;\">#<strong> ifconfig eth0 -promise<\/strong><\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\"><strong>2-PING Command<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">PING\u00a0(Packet INternet Groper) command is the best way to test connectivity between\u00a0two nodes. Whether it is\u00a0Local Area Network\u00a0(LAN) or\u00a0Wide Area Network\u00a0(WAN). Ping use\u00a0ICMP\u00a0(Internet Control Message Protocol) to communicate to other devices. You can ping host name of\u00a0ip address\u00a0using below command.<\/span><\/p>\n<pre><span style=\"color: #000000;\"># ping 4.4.4.4<\/span>\r\n\r\n<span style=\"color: #000000;\"># ping www.hentati.com<\/span>\r\n\r\n\r\n<\/pre>\n<p><span style=\"color: #000000;\">In\u00a0Linux\u00a0ping command keep executing until you interrupt. Ping with\u00a0-c\u00a0option exit after\u00a0N\u00a0number of request (success or error respond).<\/span><\/p>\n<pre><span style=\"color: #000000;\"># ping -c 5 www.hentati.com<\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\"><strong>3-TRACEROUTE Command<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">traceroute\u00a0is a network troubleshooting utility which shows number of hops taken to reach destination also determine packets traveling path. Below we are tracing route to global\u00a0DNS server IP Address\u00a0and able to reach destination also shows path of that packet is traveling.<\/span><\/p>\n<pre><span style=\"color: #000000;\"># traceroute 4.4.4.4<\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\"><strong>4-NETSTAT Command<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">Netstat\u00a0(Network Statistic) command display connection info, routing table information etc. To displays routing table information use option as\u00a0-r.<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong># netstat -r<\/strong><\/span>\r\n\r\n<span style=\"color: #000000;\">Kernel IP routing table<\/span>\r\n\r\n<span style=\"color: #000000;\">Destination\u00a0\u00a0\u00a0\u00a0 Gateway\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Genmask\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Flags\u00a0\u00a0 MSS Window\u00a0 irtt Iface<\/span>\r\n\r\n<span style=\"color: #000000;\">192.168.50.0\u00a0\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0255.255.255.0\u00a0\u00a0 U\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 eth0<\/span>\r\n\r\n<span style=\"color: #000000;\">link-local\u00a0\u00a0\u00a0\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 255.255.0.0\u00a0\u00a0\u00a0\u00a0 U\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 eth0<\/span>\r\n\r\n<span style=\"color: #000000;\">default\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 192.168.50.1\u00a0\u00a0\u00a0 0.0.0.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 UG\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 eth0<\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\"><strong>5-DIG Command<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">Dig\u00a0(domain information groper) query\u00a0DNS\u00a0related information like\u00a0A Record,\u00a0CNAME,\u00a0MX Record\u00a0etc. This command mainly use to troubleshoot\u00a0DNS\u00a0related query.<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong># dig www.hentati.com<\/strong>; &lt;&lt;&gt;&gt; DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 &lt;&lt;&gt;&gt; www.hentati.com<\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\"><strong>6-NSLOOKUP Command<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">nslookup\u00a0command also use to find out\u00a0DNS\u00a0related query. The following examples shows\u00a0A Record\u00a0(IP Address) of\u00a0tecmint.com.<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong># nslookup www.hentati.com<\/strong><\/span>\r\n\r\n<span style=\"color: #000000;\">Server:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4.2.2.2<\/span>\r\n\r\n<span style=\"color: #000000;\">Address:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4.2.2.2#53<\/span>\r\n\r\n<span style=\"color: #000000;\">Non-authoritative answer:<\/span>\r\n\r\n<span style=\"color: #000000;\">www.hentati.com canonical name = tecmint.com.<\/span>\r\n\r\n<span style=\"color: #000000;\">Name:\u00a0\u00a0 hentati.com<\/span>\r\n\r\n<span style=\"color: #000000;\">Address: 50.116.66.136<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\"><strong>7-ROUTE Command<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">route\u00a0command also shows and manipulate\u00a0ip\u00a0routing table. To see default routing table in\u00a0Linux, type the following command.<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong># route<\/strong><\/span>\r\n\r\n<span style=\"color: #000000;\">Kernel IP routing table<\/span>\r\n\r\n<span style=\"color: #000000;\">Destination\u00a0\u00a0\u00a0\u00a0 Gateway\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Genmask\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Flags Metric Ref\u00a0\u00a0\u00a0 Use Iface<\/span>\r\n\r\n<span style=\"color: #000000;\">192.168.50.0\u00a0\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 255.255.255.0 \u00a0\u00a0U\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 eth0<\/span>\r\n\r\n<span style=\"color: #000000;\">link-local\u00a0\u00a0\u00a0\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 255.255.0.0\u00a0\u00a0\u00a0\u00a0 U\u00a0\u00a0\u00a0\u00a0 1002\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 eth0<\/span>\r\n\r\n<span style=\"color: #000000;\">default\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 192.168.50.1\u00a0\u00a0\u00a0 0.0.0.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 UG\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 eth0<\/span>\r\n\r\n<span style=\"color: #000000;\">Adding, deleting routes and default Gateway with following commands.<\/span>\r\n\r\n<span style=\"color: #000000;\">Route Adding<\/span>\r\n\r\n<span style=\"color: #000000;\"><strong># route add -net 10.10.10.0\/24 gw 192.168.0.1<\/strong><\/span>\r\n\r\n<span style=\"color: #000000;\">Route Deleting<\/span>\r\n\r\n<span style=\"color: #000000;\"><strong># route del -net 10.10.10.0\/24 gw 192.168.0.1<\/strong><\/span>\r\n\r\n<span style=\"color: #000000;\">Adding default Gateway<\/span>\r\n\r\n<span style=\"color: #000000;\"><strong># route add default gw 192.168.0.1<\/strong><\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\"><strong>8-HOST Command<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">host\u00a0command to find name to\u00a0IP\u00a0or\u00a0IP\u00a0to name in\u00a0IPv4\u00a0or\u00a0IPv6\u00a0and also query\u00a0DNS\u00a0records.<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong># host www.google.com<\/strong><\/span>\r\n\r\n<span style=\"color: #000000;\">www.google.com has address 173.194.38.180<\/span>\r\n\r\n<span style=\"color: #000000;\">www.google.com has address 173.194.38.176<\/span>\r\n\r\n<span style=\"color: #000000;\">www.google.com has address 173.194.38.177<\/span>\r\n\r\n<span style=\"color: #000000;\">www.google.com has address 173.194.38.178<\/span>\r\n\r\n<span style=\"color: #000000;\">www.google.com has address 173.194.38.179<\/span>\r\n\r\n<span style=\"color: #000000;\">www.google.com has IPv6 address 2404:6800:4003:802::1014<\/span><\/pre>\n<p><span style=\"color: #000000;\">Using\u00a0-t\u00a0option we can find out DNS Resource Records like\u00a0CNAME,\u00a0NS,\u00a0MX,\u00a0SOA\u00a0etc.<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong># host -t CNAME www.redhat.com<\/strong><\/span><\/pre>\n<p><span style=\"color: #000000;\">www.redhat.com is an alias for wildcard.redhat.com.edgekey.net.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\"><strong>9-ARP Command<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">ARP\u00a0(Address Resolution Protocol) is useful to\u00a0view\u00a0\/\u00a0add\u00a0the contents of the kernel\u2019s\u00a0ARP tables. To see default table use the command as.<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong># arp -e<\/strong><\/span>\r\n\r\n<span style=\"color: #000000;\">Address\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 HWtype\u00a0 HWaddress\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Flags Mask\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Iface<\/span>\r\n\r\n<span style=\"color: #000000;\">192.168.50.1\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ether\u00a0\u00a0 00:50:56:c0:00:08\u00a0\u00a0 C\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 eth0<\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\"><strong>10-ETHTOOL Command<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">ethtool\u00a0is a replacement of\u00a0mii-tool. It is to view, setting speed and duplex of your\u00a0Network Interface Card\u00a0(NIC). You can set duplex permanently in\u00a0\/etc\/sysconfig\/network-scripts\/ifcfg-eth0\u00a0with\u00a0ETHTOOL_OPTS\u00a0variable.<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong># ethtool eth0<\/strong><\/span>\r\n\r\n<span style=\"color: #000000;\">Settings for eth0:<\/span>\r\n\r\n<span style=\"color: #000000;\">Current message level: 0x00000007 (7)<\/span>\r\n\r\n<span style=\"color: #000000;\">Link detected: yes<\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\"><strong>11-IWCONFIG Command<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">iwconfig\u00a0command in\u00a0Linux\u00a0is use to configure a\u00a0wireless network interface. You can see and set the basic\u00a0Wi-Fi\u00a0details like\u00a0SSID\u00a0channel and encryption. You can refer man page of\u00a0iwconfig\u00a0to know more.<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong># iwconfig [interface]<\/strong><\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\"><strong>12-HOSTNAME Command<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">hostname\u00a0is to identify in a network. Execute\u00a0hostname\u00a0command to see the hostname of your box. You can set hostname permanently in\u00a0\/etc\/sysconfig\/network. Need to reboot box once set a proper hostname.<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong># hostname<\/strong><\/span>\r\n\r\n<span style=\"color: #000000;\">hentati.com<\/span>\r\n\r\n\r\n<\/pre>\n<h2><span style=\"color: #000000;\"><strong>13-GUI tool system-config-network<\/strong><\/span><\/h2>\n<p><span style=\"color: #000000;\">Type\u00a0system-config-network\u00a0in command prompt to configure network setting and you will get nice\u00a0Graphical User Interface\u00a0(GUI) which may also use to configure\u00a0IP Address,\u00a0Gateway,\u00a0DNS\u00a0etc. as shown below image.<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong># system-config-network<\/strong><\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Computers are connected in a network to exchange information or resources each other. Two or more computer connected through network media called\u00a0computer network. There are number of network devices or &#8230;<\/p>\n","protected":false},"author":1,"featured_media":207,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/posts\/87"}],"collection":[{"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/comments?post=87"}],"version-history":[{"count":6,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/posts\/87\/revisions"}],"predecessor-version":[{"id":647,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/posts\/87\/revisions\/647"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/media\/207"}],"wp:attachment":[{"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/media?parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/categories?post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/tags?post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}