一、查看及测试网络配置
1.查看网络接口信息
ifconfig [-a] [接口名] -a 查看所有接口,不论接口是否活跃 [接口名] 只显指定接口
 

  1. [root@localhost ~]# ifconfig -a  
  2. eth0      Link encap:Ethernet  HWaddr 00:0C:29:75:78:09    
  3.           inet addr:192.168.2.2  Bcast:192.168.2.255  Mask:255.255.255.0  
  4.           inet6 addr: fe80::20c:29ff:fe75:7809/64 Scope:Link  
  5.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  
  6.           RX packets:97692 errors:0 dropped:0 overruns:0 frame:0  
  7.           TX packets:507 errors:0 dropped:0 overruns:0 carrier:0  
  8.           collisions:0 txqueuelen:1000   
  9.           RX bytes:5901878 (5.6 MiB)  TX bytes:101999 (99.6 KiB)  
  10.           Interrupt:59 Base address:0x2000   
  11.  
  12. lo        Link encap:Local Loopback    
  13.           inet addr:127.0.0.1  Mask:255.0.0.0  
  14.           inet6 addr: ::1/128 Scope:Host  
  15.           UP LOOPBACK RUNNING  MTU:16436  Metric:1  
  16.           RX packets:24 errors:0 dropped:0 overruns:0 frame:0  
  17.           TX packets:24 errors:0 dropped:0 overruns:0 carrier:0  
  18.           collisions:0 txqueuelen:0   
  19.           RX bytes:1904 (1.8 KiB)  TX bytes:1904 (1.8 KiB)  
  20.  
  21. sit0      Link encap:IPv6-in-IPv4    
  22.           NOARP  MTU:1480  Metric:1  
  23.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  24.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  25.           collisions:0 txqueuelen:0   
  26.           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)  
  27.  
  28. [root@localhost ~]# ifconfig eth0  
  29. eth0      Link encap:Ethernet  HWaddr 00:0C:29:75:78:09    
  30.           inet addr:192.168.2.2  Bcast:192.168.2.255  Mask:255.255.255.0  
  31.           inet6 addr: fe80::20c:29ff:fe75:7809/64 Scope:Link  
  32.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  
  33.           RX packets:97860 errors:0 dropped:0 overruns:0 frame:0  
  34.           TX packets:548 errors:0 dropped:0 overruns:0 carrier:0  
  35.           collisions:0 txqueuelen:1000   
  36.           RX bytes:5912602 (5.6 MiB)  TX bytes:107449 (104.9 KiB)  
  37.           Interrupt:59 Base address:0x2000  

2.测试网络连接状态 ping [-c 次数] 目标主机IP或名称
 

  1. [root@localhost ~]# ping -c 1 192.168.1.1  
  2. PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.  
  3. 64 bytes from 192.168.1.1: icmp_seq=1 ttl=63 time=2.00 ms  
  4.  
  5. --- 192.168.1.1 ping statistics ---  
  6. 1 packets transmitted, 1 received, 0% packet loss, time 0ms  
  7. rtt min/avg/max/mdev = 2.001/2.001/2.001/0.000 ms  
  8. [root@localhost ~]# ping -c 2 192.168.2.2  
  9. PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.  
  10. 64 bytes from 192.168.2.2: icmp_seq=1 ttl=64 time=0.017 ms  
  11. 64 bytes from 192.168.2.2: icmp_seq=2 ttl=64 time=0.020 ms  
  12.  
  13. --- 192.168.2.2 ping statistics ---  
  14. 2 packets transmitted, 2 received, 0% packet loss, time 1015ms  
  15. rtt min/avg/max/mdev = 0.017/0.018/0.020/0.004 ms 


3.查看主机路由信息 route [-n] -n 使用数字显示(速度比较快)
 

  1. [root@localhost ~]# route -n  
  2. Kernel IP routing table  
  3. Destination     Gateway         Genmask         Flags Metric Ref    Use Iface  
  4. 192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0  
  5. 169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0  
  6. 0.0.0.0         192.168.2.1     0.0.0.0         UG    0      0        0 eth0  
  7. [root@localhost ~]# netstat -rn  
  8. Kernel IP routing table  
  9. Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface  
  10. 192.168.2.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0  
  11. 169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0  
  12. 0.0.0.0         192.168.2.1     0.0.0.0         UG        0 0          0 eth0 

4.跟踪数据包所经过的路由 traceroute 目标主机IP或名称
 

  1. [root@localhost ~]# traceroute 192.168.1.1  
  2. traceroute to 192.168.1.1 (192.168.1.1), 30 hops max, 40 byte packets  
  3.  1   (192.168.2.1)  0.396 ms  0.365 ms  0.332 ms 


5.查看主机名称 hostname
 

  1. [root@localhost ~]# hostname  
  2. localhost.localdomain 

6.测试DNS服务器是否能正常解析
nslookup 目标主机名或IP [DNS服务器IP]
 

  1.  
  2. [root@localhost ~]# nslookup www.baidu.com  
  3. Server:         192.168.222.2  
  4. Address:        192.168.222.2#53  
  5.  
  6. Non-authoritative answer:  
  7. www.baidu.com   canonical name = www.a.shifen.com.  
  8. Name:   www.a.shifen.com  
  9. Address: 119.75.218.77  
  10. Name:   www.a.shifen.com  
  11. Address: 119.75.217.56  
  12.  
  13. [root@localhost ~]# nslookup www.google.com  
  14. Server:         192.168.222.2  
  15. Address:        192.168.222.2#53  
  16.  
  17. Non-authoritative answer:  
  18. www.google.com  canonical name = www.l.google.com.  
  19. Name:   www.l.google.com  
  20. Address: 74.125.128.147  
  21. Name:   www.l.google.com  
  22. Address: 74.125.128.99  
  23. Name:   www.l.google.com  
  24. Address: 74.125.128.103  
  25. Name:   www.l.google.com  
  26. Address: 74.125.128.104  
  27. Name:   www.l.google.com  
  28. Address: 74.125.128.105  
  29. Name:   www.l.google.com  
  30. Address: 74.125.128.106 


7.查看网络连接状态
netstat [-anrltup]
-a显示所有连接 -n用数字显示 -r显示路由表 -l显示处于监听状态的进程
-t显示TCP进程 -u显示UDP进程 -p显示进程号进程名信息
 

  1. [root@localhost ~]# netstat -a  
  2. Active Internet connections (servers and established)  
  3. Proto Recv-Q Send-Q Local Address               Foreign Address             State        
  4. tcp        0      0 *:sunrpc                    *:*                         LISTEN        
  5. tcp        0      0 *:ssh                       *:*                         LISTEN        
  6. getnameinfo failed  
  7. getnameinfo failed  
  8. tcp        0      0 [UNKNOWN]:ssh               [UNKNOWN]:49913             ESTABLISHED   
  9. getnameinfo failed  
  10. getnameinfo failed  
  11. tcp        0      0 [UNKNOWN]:ssh               [UNKNOWN]:56922             ESTABLISHED   
  12. getnameinfo failed  
  13. getnameinfo failed  
  14. tcp        0   5396 [UNKNOWN]:ssh               [UNKNOWN]:56588             ESTABLISHED   
  15. udp        0      0 *:47133                     *:*                                       
  16. udp        0      0 *:mdns                      *:*                                       
  17. udp        0      0 *:sunrpc                    *:*                                       
  18. udp        0      0 *:41938                     *:*                                       
  19. udp        0      0 *:mdns                      *:*                                       
  20. raw        0      0 *:icmp                      *:*                         7             
  21. raw        0      0 *:icmp                      *:*                         7             
  22. Active UNIX domain sockets (servers and established)  
  23. Proto RefCnt Flags       Type       State         I-Node Path  
  24. unix  2      [ ACC ]     STREAM     LISTENING     7453   /var/run/acpid.socket  
  25. unix  2      [ ACC ]     STREAM     LISTENING     7726   /tmp/.font-unix/fs7100  
  26. unix  2      [ ACC ]     STREAM     LISTENING     48069  /tmp/ssh-AEZfUj4473/agent.4473  
  27. unix  2      [ ACC ]     STREAM     LISTENING     48155  /tmp/ssh-zzVwKC4508/agent.4508  
  28. unix  2      [ ACC ]     STREAM     LISTENING     9324   @/tmp/fam-root-  
  29. unix  2      [ ACC ]     STREAM     LISTENING     50663  /tmp/ssh-uUKGrr6628/agent.6628  
  30. unix  2      [ ACC ]     STREAM     LISTENING     7691   /dev/gpmctl  
  31. unix  2      [ ACC ]     STREAM     LISTENING     7914   /var/run/avahi-daemon/socket  
  32. unix  2      [ ACC ]     STREAM     LISTENING     7960   @/var/run/hald/dbus-OlENpyyvWV  
  33. unix  2      [ ]         DGRAM                    1474   @/org/kernel/udev/udevd  
  34. unix  2      [ ]         DGRAM                    7968   @/org/freedesktop/hal/udev_event  
  35. unix  2      [ ACC ]     STREAM     LISTENING     7959   @/var/run/hald/dbus-EksVbyIVuK  
  36. unix  14     [ ]         DGRAM                    6838   /dev/log  
  37. unix  2      [ ACC ]     STREAM     LISTENING     6841   /var/run/audispd_events  
  38. unix  2      [ ACC ]     STREAM     LISTENING     7171   /var/run/dbus/system_bus_socket  
  39. unix  2      [ ACC ]     STREAM     LISTENING     7312   /var/run/pcscd.comm  
  40. unix  2      [ ]         DGRAM                    50655    
  41. unix  2      [ ]         DGRAM                    48147    
  42. unix  2      [ ]         DGRAM                    48061    
  43. unix  3      [ ]         STREAM     CONNECTED     9327   @/tmp/fam-root-  
  44. unix  3      [ ]         STREAM     CONNECTED     9326     
  45. unix  3      [ ]         STREAM     CONNECTED     9316   /var/run/dbus/system_bus_socket  
  46. unix  3      [ ]         STREAM     CONNECTED     9315     
  47. unix  3      [ ]         STREAM     CONNECTED     9127   /var/run/dbus/system_bus_socket  
  48. unix  3      [ ]         STREAM     CONNECTED     9126     
  49. unix  3      [ ]         STREAM     CONNECTED     9101   @/var/run/hald/dbus-EksVbyIVuK  
  50. unix  3      [ ]         STREAM     CONNECTED     9100     
  51. unix  3      [ ]         STREAM     CONNECTED     9092   /var/run/acpid.socket  
  52. unix  3      [ ]         STREAM     CONNECTED     9091     
  53. unix  3      [ ]         STREAM     CONNECTED     9082   @/var/run/hald/dbus-EksVbyIVuK  
  54. unix  3      [ ]         STREAM     CONNECTED     9081     
  55. unix  3      [ ]         STREAM     CONNECTED     8926   @/var/run/hald/dbus-EksVbyIVuK  
  56. unix  3      [ ]         STREAM     CONNECTED     8924     
  57. unix  3      [ ]         STREAM     CONNECTED     7963   @/var/run/hald/dbus-OlENpyyvWV  
  58. unix  3      [ ]         STREAM     CONNECTED     7962     
  59. unix  3      [ ]         STREAM     CONNECTED     7917   /var/run/dbus/system_bus_socket  
  60. unix  3      [ ]         STREAM     CONNECTED     7916     
  61. unix  3      [ ]         STREAM     CONNECTED     7911     
  62. unix  3      [ ]         STREAM     CONNECTED     7910     
  63. unix  2      [ ]         DGRAM                    7908     
  64. unix  2      [ ]         DGRAM                    7681     
  65. unix  2      [ ]         DGRAM                    7650     
  66. unix  2      [ ]         DGRAM                    7615     
  67. unix  2      [ ]         DGRAM                    7399     
  68. unix  2      [ ]         DGRAM                    7345     
  69. unix  2      [ ]         DGRAM                    7284     
  70. unix  3      [ ]         STREAM     CONNECTED     7175     
  71. unix  3      [ ]         STREAM     CONNECTED     7174     
  72. unix  3      [ ]         STREAM     CONNECTED     7111     
  73. unix  3      [ ]         STREAM     CONNECTED     7110     
  74. unix  2      [ ]         DGRAM                    6849     
  75. unix  2      [ ]         DGRAM                    6840     
  76. unix  3      [ ]         STREAM     CONNECTED     6768     
  77. unix  3      [ ]         STREAM     CONNECTED     6767     
  78. [root@localhost ~]# netstat -n  
  79. Active Internet connections (w/o servers)  
  80. Proto Recv-Q Send-Q Local Address               Foreign Address             State        
  81. tcp        0    132 ::ffff:192.168.2.2:22       ::ffff:192.168.2.111:49913  ESTABLISHED   
  82. tcp        0      0 ::ffff:192.168.2.2:22       ::ffff:192.168.2.111:56922  ESTABLISHED   
  83. tcp        0   5396 ::ffff:192.168.2.2:22       ::ffff:192.168.2.111:56588  ESTABLISHED   
  84. Active UNIX domain sockets (w/o servers)  
  85. Proto RefCnt Flags       Type       State         I-Node Path  
  86. unix  2      [ ]         DGRAM                    1474   @/org/kernel/udev/udevd  
  87. unix  2      [ ]         DGRAM                    7968   @/org/freedesktop/hal/udev_event  
  88. unix  14     [ ]         DGRAM                    6838   /dev/log  
  89. unix  2      [ ]         DGRAM                    50655    
  90. unix  2      [ ]         DGRAM                    48147    
  91. unix  2      [ ]         DGRAM                    48061    
  92. unix  3      [ ]         STREAM     CONNECTED     9327   @/tmp/fam-root-  
  93. unix  3      [ ]         STREAM     CONNECTED     9326     
  94. unix  3      [ ]         STREAM     CONNECTED     9316   /var/run/dbus/system_bus_socket  
  95. unix  3      [ ]         STREAM     CONNECTED     9315     
  96. unix  3      [ ]         STREAM     CONNECTED     9127   /var/run/dbus/system_bus_socket  
  97. unix  3      [ ]         STREAM     CONNECTED     9126     
  98. unix  3      [ ]         STREAM     CONNECTED     9101   @/var/run/hald/dbus-EksVbyIVuK  
  99. unix  3      [ ]         STREAM     CONNECTED     9100     
  100. unix  3      [ ]         STREAM     CONNECTED     9092   /var/run/acpid.socket  
  101. unix  3      [ ]         STREAM     CONNECTED     9091     
  102. unix  3      [ ]         STREAM     CONNECTED     9082   @/var/run/hald/dbus-EksVbyIVuK  
  103. unix  3      [ ]         STREAM     CONNECTED     9081     
  104. unix  3      [ ]         STREAM     CONNECTED     8926   @/var/run/hald/dbus-EksVbyIVuK  
  105. unix  3      [ ]         STREAM     CONNECTED     8924     
  106. unix  3      [ ]         STREAM     CONNECTED     7963   @/var/run/hald/dbus-OlENpyyvWV  
  107. unix  3      [ ]         STREAM     CONNECTED     7962     
  108. unix  3      [ ]         STREAM     CONNECTED     7917   /var/run/dbus/system_bus_socket  
  109. unix  3      [ ]         STREAM     CONNECTED     7916     
  110. unix  3      [ ]         STREAM     CONNECTED     7911     
  111. unix  3      [ ]         STREAM     CONNECTED     7910     
  112. unix  2      [ ]         DGRAM                    7908     
  113. unix  2      [ ]         DGRAM                    7681     
  114. unix  2      [ ]         DGRAM                    7650     
  115. unix  2      [ ]         DGRAM                    7615     
  116. unix  2      [ ]         DGRAM                    7399     
  117. unix  2      [ ]         DGRAM                    7345     
  118. unix  2      [ ]         DGRAM                    7284     
  119. unix  3      [ ]         STREAM     CONNECTED     7175     
  120. unix  3      [ ]         STREAM     CONNECTED     7174     
  121. unix  3      [ ]         STREAM     CONNECTED     7111     
  122. unix  3      [ ]         STREAM     CONNECTED     7110     
  123. unix  2      [ ]         DGRAM                    6849     
  124. unix  2      [ ]         DGRAM                    6840     
  125. unix  3      [ ]         STREAM     CONNECTED     6768     
  126. unix  3      [ ]         STREAM     CONNECTED     6767     
  127. [root@localhost ~]# netstat -r  
  128. Kernel IP routing table  
  129. Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface  
  130. 192.168.2.0     *               255.255.255.0   U         0 0          0 eth0  
  131. 169.254.0.0     *               255.255.0.0     U         0 0          0 eth0  
  132. default         192.168.2.1     0.0.0.0         UG        0 0          0 eth0  
  133. [root@localhost ~]# netstat -l  
  134. Active Internet connections (only servers)  
  135. Proto Recv-Q Send-Q Local Address               Foreign Address             State        
  136. tcp        0      0 *:sunrpc                    *:*                         LISTEN        
  137. tcp        0      0 *:ssh                       *:*                         LISTEN        
  138. getnameinfo failed  
  139. getnameinfo failed  
  140. getnameinfo failed  
  141. getnameinfo failed  
  142. getnameinfo failed  
  143. getnameinfo failed  
  144. udp        0      0 *:47133                     *:*                                       
  145. udp        0      0 *:mdns                      *:*                                       
  146. udp        0      0 *:sunrpc                    *:*                                       
  147. udp        0      0 *:41938                     *:*                                       
  148. udp        0      0 *:mdns                      *:*                                       
  149. raw        0      0 *:icmp                      *:*                         7             
  150. raw        0      0 *:icmp                      *:*                         7             
  151. Active UNIX domain sockets (only servers)  
  152. Proto RefCnt Flags       Type       State         I-Node Path  
  153. unix  2      [ ACC ]     STREAM     LISTENING     7453   /var/run/acpid.socket  
  154. unix  2      [ ACC ]     STREAM     LISTENING     7726   /tmp/.font-unix/fs7100  
  155. unix  2      [ ACC ]     STREAM     LISTENING     48069  /tmp/ssh-AEZfUj4473/agent.4473  
  156. unix  2      [ ACC ]     STREAM     LISTENING     48155  /tmp/ssh-zzVwKC4508/agent.4508  
  157. unix  2      [ ACC ]     STREAM     LISTENING     9324   @/tmp/fam-root-  
  158. unix  2      [ ACC ]     STREAM     LISTENING     50663  /tmp/ssh-uUKGrr6628/agent.6628  
  159. unix  2      [ ACC ]     STREAM     LISTENING     7691   /dev/gpmctl  
  160. unix  2      [ ACC ]     STREAM     LISTENING     7914   /var/run/avahi-daemon/socket  
  161. unix  2      [ ACC ]     STREAM     LISTENING     7960   @/var/run/hald/dbus-OlENpyyvWV  
  162. unix  2      [ ACC ]     STREAM     LISTENING     7959   @/var/run/hald/dbus-EksVbyIVuK  
  163. unix  2      [ ACC ]     STREAM     LISTENING     6841   /var/run/audispd_events  
  164. unix  2      [ ACC ]     STREAM     LISTENING     7171   /var/run/dbus/system_bus_socket  
  165. unix  2      [ ACC ]     STREAM     LISTENING     7312   /var/run/pcscd.comm  
  166. [root@localhost ~]# netstat -t  
  167. Active Internet connections (w/o servers)  
  168. Proto Recv-Q Send-Q Local Address               Foreign Address             State        
  169. getnameinfo failed  
  170. getnameinfo failed  
  171. tcp        0    132 [UNKNOWN]:ssh               [UNKNOWN]:49913             ESTABLISHED   
  172. getnameinfo failed  
  173. getnameinfo failed  
  174. tcp        0      0 [UNKNOWN]:ssh               [UNKNOWN]:56922             ESTABLISHED   
  175. getnameinfo failed  
  176. getnameinfo failed  
  177. tcp        0   5396 [UNKNOWN]:ssh               [UNKNOWN]:56588             ESTABLISHED   
  178. [root@localhost ~]# netstat -u  
  179. Active Internet connections (w/o servers)  
  180. Proto Recv-Q Send-Q Local Address               Foreign Address             State        
  181. [root@localhost ~]# netstat -p  
  182. Active Internet connections (w/o servers)  
  183. Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name     
  184. getnameinfo failed  
  185. getnameinfo failed  
  186. tcp        0    148 [UNKNOWN]:ssh               [UNKNOWN]:49913             ESTABLISHED 6628/2                
  187. getnameinfo failed  
  188. getnameinfo failed  
  189. tcp        0      0 [UNKNOWN]:ssh               [UNKNOWN]:56922             ESTABLISHED 4508/1                
  190. getnameinfo failed  
  191. getnameinfo failed  
  192. tcp        0   5396 [UNKNOWN]:ssh               [UNKNOWN]:56588             ESTABLISHED 4473/0                
  193. Active UNIX domain sockets (w/o servers)  
  194. Proto RefCnt Flags       Type       State         I-Node PID/Program name    Path  
  195. unix  2      [ ]         DGRAM                    1474   579/udevd           @/org/kernel/udev/udevd  
  196. unix  2      [ ]         DGRAM                    7968   2978/hald           @/org/freedesktop/hal/udev_event  
  197. unix  14     [ ]         DGRAM                    6838   2474/syslogd        /dev/log  
  198. unix  2      [ ]         DGRAM                    50655  6628/2                
  199. unix  2      [ ]         DGRAM                    48147  4508/1                
  200. unix  2      [ ]         DGRAM                    48061  4473/0                
  201. unix  3      [ ]         STREAM     CONNECTED     9327   3088/gam_server     @/tmp/fam-root-  
  202. unix  3      [ ]         STREAM     CONNECTED     9326   3086/python           
  203. unix  3      [ ]         STREAM     CONNECTED     9316   2609/dbus-daemon    /var/run/dbus/system_bus_socket  
  204. unix  3      [ ]         STREAM     CONNECTED     9315   3086/python           
  205. unix  3      [ ]         STREAM     CONNECTED     9127   2609/dbus-daemon    /var/run/dbus/system_bus_socket  
  206. unix  3      [ ]         STREAM     CONNECTED     9126   2978/hald             
  207. unix  3      [ ]         STREAM     CONNECTED     9101   2978/hald           @/var/run/hald/dbus-EksVbyIVuK  
  208. unix  3      [ ]         STREAM     CONNECTED     9100   3001/hdc              
  209. unix  3      [ ]         STREAM     CONNECTED     9092   2739/acpid          /var/run/acpid.socket  
  210. unix  3      [ ]         STREAM     CONNECTED     9091   2993/acpid.socket     
  211. unix  3      [ ]         STREAM     CONNECTED     9082   2978/hald           @/var/run/hald/dbus-EksVbyIVuK  
  212. unix  3      [ ]         STREAM     CONNECTED     9081   2991/event0           
  213. unix  3      [ ]         STREAM     CONNECTED     8926   2978/hald           @/var/run/hald/dbus-EksVbyIVuK  
  214. unix  3      [ ]         STREAM     CONNECTED     8924   2993/acpid.socket     
  215. unix  3      [ ]         STREAM     CONNECTED     7963   2978/hald           @/var/run/hald/dbus-OlENpyyvWV  
  216. unix  3      [ ]         STREAM     CONNECTED     7962   2979/hald-runner      
  217. unix  3      [ ]         STREAM     CONNECTED     7917   2609/dbus-daemon    /var/run/dbus/system_bus_socket  
  218. unix  3      [ ]         STREAM     CONNECTED     7916   2961/avahi-daemon:    
  219. unix  3      [ ]         STREAM     CONNECTED     7911   2962/avahi-daemon:    
  220. unix  3      [ ]         STREAM     CONNECTED     7910   2961/avahi-daemon:    
  221. unix  2      [ ]         DGRAM                    7908   2961/avahi-daemon:    
  222. unix  2      [ ]         DGRAM                    7681   2809/xinetd           
  223. unix  2      [ ]         DGRAM                    7650   2841/crond            
  224. unix  2      [ ]         DGRAM                    7615   2825/gpm              
  225. unix  2      [ ]         DGRAM                    7399   2714/automount        
  226. unix  2      [ ]         DGRAM                    7345   2693/hidd             
  227. unix  2      [ ]         DGRAM                    7284   2658/pcscd            
  228. unix  3      [ ]         STREAM     CONNECTED     7175   2609/dbus-daemon      
  229. unix  3      [ ]         STREAM     CONNECTED     7174   2609/dbus-daemon      
  230. unix  3      [ ]         STREAM     CONNECTED     7111   2580/rpc.idmapd       
  231. unix  3      [ ]         STREAM     CONNECTED     7110   2580/rpc.idmapd       
  232. unix  2      [ ]         DGRAM                    6849   2478/klogd            
  233. unix  2      [ ]         DGRAM                    6840   2440/audispd          
  234. unix  3      [ ]         STREAM     CONNECTED     6768   2438/auditd           
  235. unix  3      [ ]         STREAM     CONNECTED     6767   2440/audispd 


8.查看ARP缓存记录 arp -n
      清空ARP缓存记录 arp -n|awk '/^[1-9]/{print "arp -d  " $1}'|sh -x
 

  1. [root@localhost ~]# arp -n  
  2. Address                  HWtype  HWaddress           Flags Mask            Iface  
  3. 192.168.2.111            ether   40:16:9F:F3:85:E7   C                     eth0  
  4. 192.168.2.1              ether   B0:48:7A:2E:98:D4   C                     eth0  
  5. 192.168.2.222            ether   00:21:CC:4A:A8:60   C                     eth0  
  6. [root@localhost ~]# arp -n|awk '/^[1-9]/{print "arp -d  " $1}'|sh -x  
  7. + arp -d 192.168.2.111  
  8. + arp -d 192.168.2.1  
  9. + arp -d 192.168.2.222  
  10. [root@localhost ~]# arp -n  
  11. Address                  HWtype  HWaddress           Flags Mask            Iface  
  12. 192.168.2.111            ether   40:16:9F:F3:85:E7   C                     eth0  
  13. 192.168.2.1              ether   B0:48:7A:2E:98:D4   C                     eth0  
  14. 192.168.2.222                    (incomplete)                              eth0 


二、使用命令调整网络参数(临时生效)
1.修改网卡参数
ifconfig 接口名 ip地址 [netmask 子网掩码]

ifconfig 接口名 ip地址[/网络前缀]
ifconfig 接口名 down[/up]
ifconfig 接口名 hw ether 接口MAC地址
 

  1. [root@localhost ~]# ifconfig eth0 192.168.1.1 255.255.255.0  
  2. [root@localhost ~]# ifconfig eth0 192.168.1.1/24  
  3. [root@localhost ~]# ifconfig eth0 down  
  4. [root@localhost ~]# ifconfig eth0 up  
  5. [root@localhost ~]# ifdown eth0;ifup eth0  
  6. [root@localhost ~]# ifconfig eth0 hw ether 00:11:22:33:44:55 


2.设置路由记录
route add -net 网络地址/网络前缀 gw 下一跳IP

route add -host 主机IP gw 下一跳IP

route add default gw 下一跳IP

route del -net 网络地址/网络前缀 [gw 下一跳IP]

route del -host 主机IP [gw 下一跳IP]

route del default [gw 下一跳IP]

3.配置主机名 hostname 主机名
 

  1. [root@localhost ~]# hostname Mail_Server  
  2. [root@localhost ~]# bash  
  3. [root@Mail_Server ~]# hostname  
  4. Mail_Server 

4.配置静态arp arp -s 主机IP地址 主机MAC地址
 

  1. [root@localhost ~]# arp -n  
  2. Address                  HWtype  HWaddress           Flags Mask            Iface  
  3. 192.168.2.111            ether   40:16:9F:F3:85:E7   C                     eth0  
  4. [root@localhost ~]# arp -s 192.168.2.222 00:11:22:33:44:55  
  5. [root@localhost ~]# arp -n  
  6. Address                  HWtype  HWaddress           Flags Mask            Iface  
  7. 192.168.2.111            ether   40:16:9F:F3:85:E7   C                     eth0  
  8. 192.168.2.222            ether   00:11:22:33:44:55   CM                    eth0 


三、通过配置文件修改网络参数
1.网卡参数
/etc/sysconfig/network-scripts/ifcfg-接口名
DEVICE=接口名 ONBOOT=yes/no BOOTPROTO=static/dhcp
IPADDR=IP地址 NETMASK=子网掩码 GATEWAY=网关IP
 

  1. [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0  
  2. # Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]  
  3. DEVICE=eth0 
  4. BOOTPROTO=none 
  5. ONBOOT=yes 
  6. HWADDR=00:0c:29:75:78:09  
  7. TYPE=Ethernet 
  8. NETMASK=255.255.255.0  
  9. IPADDR=192.168.2.2  
  10. GATEWAY=192.168.2.1 

2.修改主机名
/etc/sysconfig/network
NETWORKING=yes/no NETWORKING_IPV6=yes/no HOSTNAME=主机名
 

  1. [root@localhost ~]# cat /etc/sysconfig/network  
  2. NETWORKING=yes 
  3. NETWORKING_IPV6=no 
  4. HOSTNAME=localhost.localdomain 


3.配置DNS服务器IP
/etc/resolv.conf
nameserver DNS服务器IP
 

  1. [root@localhost ~]# cat /etc/resolv.conf   
  2. nameserver 202.106.0.20  
  3. nameserver 202.106.148.1  
  4. search localdomain 


4.配置本地的域名解析记录
/etc/hosts
IP地址 主机名
 

  1. [root@localhost ~]# cat /etc/hosts  
  2. # Do not remove the following line, or various programs  
  3. # that require network functionality will fail.  
  4. 127.0.0.1               localhost.localdomain localhost  
  5. ::1             localhost6.localdomain6 localhost6 



四、使用DHCP动态配置主机地址
1.安装
rpm -ivh /media/Server/dhcp-版本信息

2.修改主配置文件
cp /usr/share/doc/dhcp-版本/dhcpd.conf.sample /etc/dhcpd.conf
vi /etc/dhcpd.conf
3.重要配置项
option routers 网关IP;

option sub-netmask 子网掩码;

option domain-name-servers 首选DNS,备用DNS;
rang 开始IP 结束IP;
default-lease-time 默认租约时间;
max-lease-time 最大租约时间;
hardware ethernet 主机MAC地址;

fixed-address 保留IP地址;
4.启动服务
service dhcpd start
 

  1.  
  2. [root@localhost ~]# mount /dev/cdrom /media/  
  3. mount: block device /dev/cdrom is write-protected, mounting read-only  
  4. [root@localhost ~]# cd /media/Server/  
  5. [root@localhost Server]# rpm -ivh dhcp-*.rpm  
  6. warning: dhcp-3.0.5-18.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186  
  7. Preparing...                ########################################### [100%]  
  8.    1:dhcp                   ########################################### [ 50%]  
  9.    2:dhcp-devel             ########################################### [100%]  
  10. [root@localhost Server]# cd  
  11. [root@localhost ~]# cat /etc/dhcpd.conf   
  12. #  
  13. # DHCP Server Configuration file.  
  14. #   see /usr/share/doc/dhcp*/dhcpd.conf.sample    
  15. #[root@localhost ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.cnf   
  16. cp:是否覆盖“/etc/dhcpd.conf”? y  
  17. [root@localhost ~]# vi /etc/dhcpd.conf   
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.       1 ddns-update-style interim;  
  25.       2 ignore client-updates;  
  26.       3   
  27.       4 subnet 192.168.2.0 netmask 255.255.255.0 {  
  28.       5   
  29.       6 # --- default gateway  
  30.       7         option routers                  192.168.2.1;  
  31.       8         option subnet-mask              255.255.255.0;  
  32.       9   
  33.       1 ddns-update-style interim;  
  34.       2 ignore client-updates;  
  35.       3   
  36.       4 subnet 192.168.2.0 netmask 255.255.255.0 {  
  37.       5   
  38.       6 # --- default gateway  
  39.       7         option routers                  192.168.2.1;  
  40.       8         option subnet-mask              255.255.255.0;  
  41.       9   
  42.      10         option nis-domain               "domain.org";  
  43.      11         option domain-name              "domain.org";  
  44.      12         option domain-name-servers      202.106.0.20,202.106.148.1;  
  45.      13   
  46.      14         option time-offset              -18000; # Eastern Standard Time  
  47.      15 #       option ntp-servers              192.168.1.1;  
  48.      16 #       option netbios-name-servers     192.168.1.1;  
  49.      17 # --- Selects point-to-point node (default is hybrid). Don't change this  
  50.          unless  
  51.      18 # -- you understand Netbios very well  
  52.      19 #       option netbios-node-type 2;  
  53.      20   
  54.      21         range dynamic-bootp 192.168.2.128 192.168.2.254;  
  55.      22         default-lease-time 21600;  
  56. "/etc/dhcpd.conf" 31L, 872C written  
  57. [root@localhost ~]# service dhcpd restart  
  58. 启动 dhcpd:                                               [确定]  
  59. [root@localhost ~]# chkconfig dhcpd on 


5.设置在哪块网卡提供DHCP服务
/etc/sysconfig/dhcpd
DHCPARGS=”接口名”
6.租期数据库文件
/var/lib/dhcpd/dhcpd.lease
 

  1. [root@localhost ~]# cat /etc/sysconfig/dhcpd   
  2. # Command line options here  
  3. DHCPDARGS="eth0" 
  4. [root@localhost ~]# cat /var/lib/dhcpd/dhcpd.leases  
  5. # All times in this file are in UTC (GMT), not your local timezone.   This is  
  6. # not a bug, so please don't ask about it.   There is no portable way to  
  7. # store leases in the local timezone, so please don't request this as a  
  8. # feature.   If this is inconvenient or confusing to you, we sincerely  
  9. # apologize.   Seriously, though - don't ask.  
  10. # The format of this file is documented in the dhcpd.leases(5) manual page.  
  11. # This lease file was written by isc-dhcp-V3.0.5-RedHat  
  12.  
  13. lease 192.168.2.254 {  
  14.   starts 5 2012/04/06 10:15:22;  
  15.   ends 5 2012/04/06 16:15:22;  
  16.   tstp 5 2012/04/06 16:15:22;  
  17.   binding state active;  
  18.   next binding state free;  
  19.   hardware ethernet 00:0c:29:63:46:4f;  
  20.   uid "\001\000\014)cFO";  
  21.   client-hostname "benet-5";