9.8. Config TCP/IP Networking manually -command line

The ifconfig utility is the tool used to set up and configure your network card. You should understand this command in the event you need to configure the network by hand. An important note to take care with is when using ifconfig to configure your network devices; the settings will not survive a reboot. To assign the eth0 interface the IP-address of 208.164.186.2 use the command:

         [root@deep] /#ifconfig eth0 208.164.186.2 netmask 255.255.255.0
         

Tip: Usually, the pratice is to configure or change the TCP/IP networking manually only to make some test on the server. If you want to keep your TCP/IP values, it's preferable to set them in the files related to networking functionality.

To display all the interfaces you have on your server, use the command:

         [root@deep] /#ifconfig
         
The output should look something like this:

           
         eth0	Link encap:Ethernet  HWaddr 00:E0:18:90:1B:56  
         inet addr:208.164.186.2  Bcast:208.164.186.255  Mask:255.255.255.0
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:1295 errors:0 dropped:0 overruns:0 frame:0
         TX packets:1163 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:100 
         Interrupt:11 Base address:0xa800 

         lo	Link encap:Local Loopback  
         inet addr:127.0.0.1  Mask:255.0.0.0
         UP LOOPBACK RUNNING  MTU:3924  Metric:1
         RX packets:139 errors:0 dropped:0 overruns:0 frame:0
         TX packets:139 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0 
         
         
If the ifconfig tool is invoked without any parameters, it displays all interfaces you have configured. An option of -a shows the inactive one as well.

To display all interfaces as well as inactive interfaces you may have, use the command:

         [root@deep] /#ifconfig -a
         
The output should look something like this:
         
         
         eth0	Link encap:Ethernet  HWaddr 00:E0:18:90:1B:56  
         inet addr:208.164.186.2  Bcast:208.164.186.255  Mask:255.255.255.0
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:1295 errors:0 dropped:0 overruns:0 frame:0
         TX packets:1163 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:100 
         Interrupt:11 Base address:0xa800 

         eth1	Link encap:Ethernet  HWaddr 00:E0:18:90:1B:56  
         inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:1295 errors:0 dropped:0 overruns:0 frame:0
         TX packets:1163 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:100 
         Interrupt:5 Base address:0xa320

         lo	Link encap:Local Loopback  
         inet addr:127.0.0.1  Mask:255.0.0.0
         UP LOOPBACK RUNNING  MTU:3924  Metric:1
         RX packets:139 errors:0 dropped:0 overruns:0 frame:0
         TX packets:139 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         
         
It is important to note that the settings configured with the ifconfig toll for your network devices will not survive a reboot.

To assign the default gateway for 208.164.186.12 use the command:

         [root@deep] /#route add default gw 208.164.186.1
         
In this example, the default route is set up to go to 208.164.186.12, your router. Once again, if you want to keep your default gateway value, it's preferable to set in it the files related to networking functionality -/etc/sysconfig/network.

Verify that you can reach your hosts. Choose a host from your network, for instance 208.164.186.1. Use the command:

         [root@deep] /#ping 208.164.186.1
         
The output should look something like this:

         [root@deep networking]# ping 208.164.186.1
         PING 208.164.186.1 (208.164.186.1) from 208.164.186.2 : 56 data bytes
         64 bytes from 208.164.186.2: icmp_seq=0 ttl=128 time=1.0 ms
         64 bytes from 208.164.186.2: icmp_seq=1 ttl=128 time=1.0 ms
         64 bytes from 208.164.186.2: icmp_seq=2 ttl=128 time=1.0 ms
         64 bytes from 208.164.186.2: icmp_seq=3 ttl=128 time=1.0 ms

         --- 208.164.186.1 ping statistics ---
         4 packets transmitted, 4 packets received, 0% packet loss
         round-trip min/avg/max = 1.0/1.0/1.0 ms
         
         

You should now display the routing information with the command route to see if both hosts have the correct routing entry. Use the command:

         [root@deep] /#route -n
         
The output should look something like this:

         Kernel         IP                      routing table
         Destination	Gateway	Genmask	Flags	Metric	Ref 	Use	Iface
         208.164.186.2	0.0.0.0	255.255.255.255	UH	0	0	0	eth0
         208.164.186.0	208.164.186.2	255.255.255.0	UG	0	0	0	eth0
         208.164.186.0	0.0.0.0	255.255.255.0	U	0	0	0	eth0
         127.0.0.0	0.0.0.0	255.0.0.0	U	0	0	0	lo
         
         

To check the status of the interfaces quickly, use the netstat -i command, as follows:

         [root@deep] /#netstat -i
         
The output should look something like this:

         Kernel Interface table
         Iface	MTU	Met	RX-OK	RX-ERR	RX-DRP	RX-OVR	TX-OK	TX-ERR	TX-DRP	TX-OVR Flg
         eth0	1500	0	4236	0	0	0	3700	0	0	0	BRU	
         lo	3924	0	13300	0	0	0	13300	0	0	0	LRU
         ppp0	1500	0	14	1	0	0	16	0	0	0	PRU
         
         

Another useful netstat option is -t, which shows all active TCP connections. Following is a typical result of netstat -t:

         [root@deep] /#netstat -t
         
The output should look something like this:

         Active Internet connections (w/o servers)
         Proto	Recv-Q	Send-Q	Local Address	Foreign Address	State      
         Tcp	0	0	deep.openar:netbios-ssn	gate.openna.com:1045	ESTABLISHED 
         Tcp	0	0	localhost:1032	localhost:1033	ESTABLISHED 
         Tcp	0	0	localhost:1033	localhost:1032	ESTABLISHED 
         Tcp	0	0	localhost:1030	localhost:1034	ESTABLISHED 
         Tcp	0	0	localhost:1031	localhost:1030	ESTABLISHED 
         Tcp	0	0	localhost:1028	localhost:1029	ESTABLISHED 
         Tcp	0	0	localhost:1029	localhost:1028	ESTABLISHED 
         Tcp	0	0	localhost:1026	localhost:1027	ESTABLISHED 
         Tcp	0	0	localhost:1027	localhost:1026	ESTABLISHED 
         Tcp	0	0	localhost:1024	localhost:1025	ESTABLISHED 
         Tcp	0	0	localhost:1025	localhost:1024	ESTABLISHED 
         
         

To shows all active and listen TCP connections, use the command:

         [root@deep] /#netstat -vat
         
The output should look something like this:

         Active Internet connections (servers and established)
         Proto Recv-Q Send-Q Local Address           	        Foreign Address                 State      
         tcp        0      0 deep.openna.co:domain 	        *:*                     	LISTEN      
         tcp        0      0 localhost:domain       	        *:*                    	        LISTEN      
         tcp        0      0 deep.openna.com:ssh   	        gate.openna.com:1682  	        ESTABLISHED 
         tcp        0      0 *:webcache              		*:*                     	LISTEN      
         tcp        0      0 deep.openar:netbios-ssn	        *:*                     	LISTEN      
         tcp        0      0 localhost:netbios-ssn  		*:*                     	LISTEN      
         tcp        0      0 localhost:1032          		localhost:1033          	ESTABLISHED 
         tcp        0      0 localhost:1033          		localhost:1032          	ESTABLISHED 
         tcp        0      0 localhost:1030          		localhost:1031          	ESTABLISHED 
         tcp        0      0 localhost:1031          		localhost:1030          	ESTABLISHED 
         tcp        0      0 localhost:1028          		localhost:1029          	ESTABLISHED 
         tcp        0      0 localhost:1029         		localhost:1028          	ESTABLISHED 
         tcp        0      0 localhost:1026          		localhost:1027          	ESTABLISHED 
         tcp        0      0 localhost:1027          		localhost:1026          	ESTABLISHED 
         tcp        0      0 localhost:1024          		localhost:1025          	ESTABLISHED 
         tcp        0      0 localhost:1025          		localhost:1024          	ESTABLISHED 
         tcp        0      0 deep.openna.com:www   	        *:*                    		LISTEN      
         tcp        0      0 deep.openna.com:https 	        *:*                    		LISTEN      
         tcp        0      0 *:389            	       		*:*                     	LISTEN      
         tcp        0      0 *:ssh       	            	*:*              		LISTEN      
         

To stop all network devices manually on your system, use the following command:

         [root@deep] /# /etc/rc.d/init.d/network stop
         

         Shutting down interface eth0	         [  OK  ]
         Disabling IPv4 packet forwarding	 [  OK  ]
         

To start all network devices manually on your system, use the following command:

         [root@deep] /# /etc/rc.d/init.d/network start

         

         Enabling IPv4 packet forwarding	  [  OK  ]
         Bringing up interface lo		  [  OK  ]
         Bringing up interface eth0	          [  OK  ]