CentOS网络配置
[color=rgb(85, 85, 85)][font=宋体, "]在centOS系统中用用于网络配置的有这么几个命令ifconfig,route,ip,netstat,ss。ifconfig与route命令正在逐渐被ip命令取代。[color=rgb(85, 85, 85)][font=宋体, "]1、ifconfig:配置网络接口[indent][font=微软雅黑, "]ifconfig -a #显示所有处于激活状态的连接(默认)[/indent][indent]ifconfig IFNAME #仅显示指定接口的信息ifconfig IFNAME ADDRESS #配置网络接口的IP地址 长格式:ifconfig IFNAME IP netmask MASK 短格式:ifconfig IFNAME IP/MASKifconfig IFNAME up #开启IFNAME网卡ifconfig IFNAME up #关闭IFNAME网卡
[/indent][color=rgb(85, 85, 85)][font=宋体, "]用ifconfig配置ip地址:[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em]9
[align=right][size=1em]10
[align=right][size=1em]11
[align=right][size=1em]12
[align=right][size=1em]13
[align=right][size=1em]14
[align=right][size=1em]15
[align=right][size=1em]16
[align=right][size=1em]17
[align=right][size=1em][size=1em][root@xiaoxiao ~]# ifconfig eth1
[size=1em]eth1 Link encap:Ethernet HWaddr 00:0C:29:D6:C9:FA
[size=1em] UP BROADCAST MULTICAST MTU:1500 Metric:1
[size=1em] RX packets:0 errors:0 dropped:0 overruns:0 frame:0
[size=1em] TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
[size=1em] collisions:0 txqueuelen:1000
[size=1em] RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[size=1em]
[size=1em][root@xiaoxiao ~]# ifconfig eth1 192.168.172.133/24 broadcast 192.168.172.255
[size=1em][root@xiaoxiao ~]# ifconfig eth1
[size=1em]eth1 Link encap:Ethernet HWaddr 00:0C:29:D6:C9:FA
[size=1em] inet addr:192.168.172.133 Bcast:192.168.172.255 Mask:255.255.255.0
[size=1em] UP BROADCAST MULTICAST MTU:1500 Metric:1
[size=1em] RX packets:0 errors:0 dropped:0 overruns:0 frame:0
[size=1em] TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
[size=1em] collisions:0 txqueuelen:1000
[size=1em] RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[color=rgb(85, 85, 85)][font=宋体, "]
[color=rgb(85, 85, 85)][font=宋体, "]2、route:配置路由表[color=rgb(85, 85, 85)][font=宋体, "]route #显示路由表信息[color=rgb(85, 85, 85)][font=宋体, "]route -n #用数字的格式显示路由信息[color=rgb(85, 85, 85)][font=宋体, "]route add -host HOST_IP gw NEXT_HOP [dev DEVICE] #添加主机路由[color=rgb(85, 85, 85)][font=宋体, "]route add -net HOST_IP gw NEXT_HOP [dev DEVICE] #添加网络路由[color=rgb(85, 85, 85)][font=宋体, "]route add default gw GW_ADD #添加默认路由[color=rgb(85, 85, 85)][font=宋体, "]route del -host HOST_IP #删除主机路由[color=rgb(85, 85, 85)][font=宋体, "]route del -net HOST_IP #删除网络路由[color=rgb(85, 85, 85)][font=宋体, "]route del default #删除默认路由[color=rgb(85, 85, 85)][font=宋体, "]显示路由表:[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em][size=1em][root@xiaoxiao ~]# route -n
[size=1em]Kernel IP routing table
[size=1em]Destination Gateway Genmask Flags Metric Ref Use Iface
[size=1em]114.114.114.114 192.168.172.3 255.255.255.255 UGH 0 0 0 eth1 #主机路由
[size=1em]192.168.172.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[size=1em]192.168.172.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
[size=1em]169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
[size=1em]0.0.0.0 192.168.172.2 0.0.0.0 UG 0 0 0 eth0 #默认路由
[color=rgb(85, 85, 85)][color=rgb(85, 85, 85)][font=宋体, "]说明:Destination表示目的网络或者目的主机,gateway需要经过的网关,Genmask子网掩码,Flags标示符(U:改路由条目生效,G:改路由条目需要使用网关地址,H:目标是主机名(host)......),Metric到目标地址(Destination)的距离(usually counted in hops),Iface对应的接口。[color=rgb(85, 85, 85)][font=宋体, "]Destination为0.0.0.0表示默认路由条目,Gateway为0.0.0.0表示该目的地址就在本网络上,不需要网关。
[color=rgb(85, 85, 85)][font=宋体, "]添加主机、网络、默认路由:[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em]9
[align=right][size=1em]10
[align=right][size=1em]11
[align=right][size=1em]12
[align=right][size=1em]13
[align=right][size=1em][size=1em][root@xiaoxiao ~]# route add -host 115.115.115.115 gw 192.168.172.3 dev eth1
[size=1em][root@xiaoxiao ~]# route add -net 116.116.116.0/24 gw 192.168.172.3 dev eth1
[size=1em][root@xiaoxiao ~]# route add default gw 192.168.172.4
[size=1em][root@xiaoxiao ~]# route -n
[size=1em]Kernel IP routing table
[size=1em]Destination Gateway Genmask Flags Metric Ref Use Iface
[size=1em]115.115.115.115 192.168.172.3 255.255.255.255 UGH 0 0 0 eth1
[size=1em]116.116.116.0 192.168.172.3 255.255.255.0 UG 0 0 0 eth1 #网络路由
[size=1em]192.168.172.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[size=1em]192.168.172.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
[size=1em]169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
[size=1em]0.0.0.0 192.168.172.4 0.0.0.0 UG 0 0 0 eth0 #仅第一个默认路由生效
[size=1em]0.0.0.0 192.168.172.2 0.0.0.0 UG 0 0 0 eth0
[color=rgb(85, 85, 85)][font=宋体, "]添加了192.168.172.4这条默认路由之后,最下面的那条路由就会失效。
[color=rgb(85, 85, 85)][font=宋体, "]删除刚刚添加的路由条目:[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em][size=1em][root@xiaoxiao ~]# route del -host 115.115.115.115
[size=1em][root@xiaoxiao ~]# route del -net 116.116.116.0/24
[size=1em][root@xiaoxiao ~]# route del default
[color=rgb(85, 85, 85)][font=宋体, "]注意:在添加路由时,网关必须和当前主机的ip地址处在同一个网段中,不然会添加失败。
[color=rgb(85, 85, 85)][font=宋体, "]3、ip。ip有很多子命令,这里只介绍常用的3个。ip link用于管理接口,ip addr用于协议地址,ip route用于管理路由。ip是一个比较新的命令,用于取代ifconfig和route,所以建议使用这个命令来配置网络的相关属性。[color=rgb(85, 85, 85)][font=宋体, "]ip link:[color=rgb(85, 85, 85)][font=宋体, "]ip link show [dev DEVICE] #显示指定接口的状态信息[color=rgb(85, 85, 85)][font=宋体, "]ip link set IFNAME {up|down} #开启或关闭网卡[color=rgb(85, 85, 85)][font=宋体, "]ip link set IFNAME promise {on|off} #开启或关闭网络的混合模式[color=rgb(85, 85, 85)][font=宋体, "]ip link set IFNAME mtu 1400 #设置网卡最大传输单元
[color=rgb(85, 85, 85)][font=宋体, "]ip add:[color=rgb(85, 85, 85)][font=宋体, "]ip addr show [dev DEVICE] #显示指定接口的地址信息[color=rgb(85, 85, 85)][font=宋体, "]ip addr flush [dev DEVICE] #清除指定接口的地址信息[color=rgb(85, 85, 85)][font=宋体, "]ip addr {add|del} ADDRESS [label IFALIAS(指定别名)] [scope] [brd BCAST_ADDRESS(指定广播地址)] dev DEVICE # 为一个接口配置地址(可以为一个接口配置多个地址)
[color=rgb(85, 85, 85)][font=宋体, "]显示,添加,删除ip地址:[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em]9
[align=right][size=1em]10
[align=right][size=1em]11
[align=right][size=1em]12
[align=right][size=1em][size=1em][root@xiaoxiao ~]# ip addr show dev eth1
[size=1em]3: eth1:
[size=1em] link/ether 00:0c:29:d6:c9:fa brd ff:ff:ff:ff:ff:ff
[size=1em][root@xiaoxiao ~]# ip addr add 192.168.172.134/24 brd 192.168.172.255 dev eth1
[size=1em][root@xiaoxiao ~]# ip addr show dev eth1
[size=1em]3: eth1:
[size=1em] link/ether 00:0c:29:d6:c9:fa brd ff:ff:ff:ff:ff:ff
[size=1em] inet 192.168.172.134/24 brd 192.168.172.255 scope global eth1
[size=1em][root@xiaoxiao ~]# ip addr del 192.168.172.134/24 dev eth1
[size=1em][root@xiaoxiao ~]# ip addr show dev eth1
[size=1em]3: eth1:
[size=1em] link/ether 00:0c:29:d6:c9:fa brd ff:ff:ff:ff:ff:ff
[color=rgb(85, 85, 85)][font=宋体, "]ip route:[color=rgb(85, 85, 85)][font=宋体, "]ip route list #列出路由信息[color=rgb(85, 85, 85)][font=宋体, "]ip route flush #清空路由表[color=rgb(85, 85, 85)][font=宋体, "]ip route add DESTINATION [via NEXT_HOP] [src SOURCE_ADDRESS] [dev DEVICE][color=rgb(85, 85, 85)][font=宋体, "] #添加路由信息(src表示来自于纳鞋底至的包)[color=rgb(85, 85, 85)][font=宋体, "]ip route add default via NEXT_HOP #添加默认路由[color=rgb(85, 85, 85)][font=宋体, "]ip route del DESTINATION #删除路由[color=rgb(85, 85, 85)][font=宋体, "]ip route del default #删除默认路由
[color=rgb(85, 85, 85)][font=宋体, "]
[color=rgb(85, 85, 85)][font=宋体, "]添加主机路由、网络路由,查看路由表:[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em][size=1em][root@xiaoxiao ~]# ip route add 115.115.115.115 via 192.168.172.5 dev eth1
[size=1em][root@xiaoxiao ~]# ip route add 115.115.116.0/24 via 192.168.172.5 dev eth1
[size=1em][root@xiaoxiao ~]# ip route list
[size=1em]115.115.115.115 via 192.168.172.5 dev eth1
[size=1em]115.115.116.0/24 via 192.168.172.5 dev eth1
[size=1em]192.168.172.0/24 dev eth0 proto kernel scope link src 192.168.172.131
[size=1em]192.168.172.0/24 dev eth1 proto kernel scope link src 192.168.172.135
[size=1em]169.254.0.0/16 dev eth0 scope link metric 1002
[color=rgb(85, 85, 85)][font=宋体, "]注意:当已经有默认路由存在时,无法用ip命令再次添加,需要先删除再进行添加[color=rgb(85, 85, 85)][font=宋体, "]
[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em]9
[align=right][size=1em]10
[align=right][size=1em]11
[align=right][size=1em][size=1em][root@xiaoxiao ~]# ip route add default via 192.168.172.136
[size=1em]RTNETLINK answers: File exists #添加失败,因为已经存在默认路由
[size=1em][root@xiaoxiao ~]# ip route del default #删除原来的默认路由
[size=1em][root@xiaoxiao ~]# ip route add default via 192.168.172.136
[size=1em][root@xiaoxiao ~]# ip route list
[size=1em]115.115.115.115 via 192.168.172.5 dev eth1
[size=1em]115.115.116.0/24 via 192.168.172.5 dev eth1
[size=1em]192.168.172.0/24 dev eth0 proto kernel scope link src 192.168.172.131
[size=1em]192.168.172.0/24 dev eth1 proto kernel scope link src 192.168.172.135
[size=1em]169.254.0.0/16 dev eth0 scope link metric 1002
[size=1em]default via 192.168.172.136 dev eth0 #添加成功
[color=rgb(85, 85, 85)][font=宋体, "]以上的配置会立即生效,但不会永久有效,重启系统或者网络服务之后,配置就会失效。若想要永久有效需要到配置文件中进行配置。
[color=rgb(85, 85, 85)][font=宋体, "]网络的相关配置文件:[color=rgb(85, 85, 85)][font=宋体, "]/etc/sysconfig/network-scripts/ifcfg-IFNAME #网络接口的配置文件[color=rgb(85, 85, 85)][font=宋体, "]/etc/hosts #完成主机名映射IP地址的功能[color=rgb(85, 85, 85)][font=宋体, "]/etc/resolv.conf #域名服务客户端的配置文件,用于指定域名服务器的地址[color=rgb(85, 85, 85)][font=宋体, "]/etc/sysconfig/network #主机最基本的网络信息,包括主机名,在系统启动使用到[color=rgb(85, 85, 85)][font=宋体, "]/etc/sysconfig/network-scripts/route-IFNAME #路由表的配置信息
[color=rgb(85, 85, 85)][font=宋体, "]1、/etc/sysconfig/network-scripts/ifcfg-IFNAME:[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em]9
[align=right][size=1em]10
[align=right][size=1em]11
[align=right][size=1em]12
[align=right][size=1em]13
[align=right][size=1em]14
[align=right][size=1em]15
[align=right][size=1em]16
[align=right][size=1em]17
[align=right][size=1em]18
[align=right][size=1em]19
[align=right][size=1em]20
[align=right][size=1em][size=1em]DEVICE=eth0 #此配置文件所关联到的设备,设备文件要与本文件名ifcfg-后面保持一致
[size=1em]TYPE=Ethernet #网络接口类型{Ethernet|bridge}
[size=1em]UUID=e6799ee4-6f92-4f00-b10d-0b5227102a1f
[size=1em]ONBOOT=no #是否在开机过程中激活此接口
[size=1em]NM_CONTROLLED=no #该设备是否被NetworkManager管理
[size=1em]BOOTPROTO=dhcp #启动协议{dhcp|none|static|bootp}
[size=1em]DEFROUTE=yes
[size=1em]IPV4_FAILURE_FATAL=yes
[size=1em]IPV6INIT=no
[size=1em]NAME="System eth0"
[size=1em]HWADDR=00:0C:29:D6:C9:F0 #mac地址
[size=1em]PEERDNS=yes #是否接受dhcp服务器指派的dns服务器地址
[size=1em]PEERROUTES=yes
[size=1em]LAST_CONNECT=1429555046
[size=1em]USERCTL={yes|no} #是否允许普通用户控制此接口
[size=1em]IPADDR= #IP地址
[size=1em]DNS1= #主DNS服务器地址
[size=1em]DNS2=
[size=1em]NETMASK= #子网掩码
[size=1em]GATEWAY= #默认网关
[color=rgb(85, 85, 85)][font=宋体, "]配置完需要重启网络服务:[color=rgb(85, 85, 85)][font=宋体, "]/etc/init.d/network restart 或 service network restart[color=rgb(85, 85, 85)][font=宋体, "]centOS7中网络服务为NetworkManager:[color=rgb(85, 85, 85)][font=宋体, "]/etc/init.d/NetworkManager restart 或 service NetworkManager restart
[color=rgb(85, 85, 85)][font=宋体, "]2、/etc/sysconfig/network-scripts/route-IFNAME: 配置静态路由(这个配置文件默认没有,需要自己添加)[color=rgb(85, 85, 85)][font=宋体, "]配置文件的格式1:每行一个路由条目[color=rgb(85, 85, 85)][font=宋体, "]DESTINATION via NETX_HOP[color=rgb(85, 85, 85)][font=宋体, "]配置文件格式2: 每三行一个路由条目[color=rgb(85, 85, 85)][font=宋体, "]ADDRESS#=DESTINATION[color=rgb(85, 85, 85)][font=宋体, "]NETMASK#=MASK[color=rgb(85, 85, 85)][font=宋体, "]GATEWAY#=GW[color=rgb(85, 85, 85)][font=宋体, "]注意:这种格式的书写方式,#表示数字,必须从0开始(第一个路由条目为0,第二个为1......),=两边没有空格
[color=rgb(85, 85, 85)][font=宋体, "]3、/etc/hosts[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em][size=1em][xiaoxiao@xiaoxiao ~]$ cat /etc/hosts
[size=1em]127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
[size=1em]::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[color=rgb(85, 85, 85)][font=宋体, "]/etc/hosts这个文件的默认内容如上,第一行是ipv4信息,第二行是ipv6信息。这是一个本地解析的配置文件,localhost,localhost.localdomain,localhost4......都会被解析成127.0.0.1。
[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em][size=1em][xiaoxiao@xiaoxiao ~]$ ping localhost -c 2
[size=1em]PING localhost (127.0.0.1) 56(84) bytes of data.
[size=1em]64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.114 ms
[size=1em]64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.105 ms
[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em][size=1em][xiaoxiao@xiaoxiao ~]$ ping localhost4 -c 2
[size=1em]PING localhost (127.0.0.1) 56(84) bytes of data.
[size=1em]64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.050 ms
[size=1em]64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.054 ms
[color=rgb(85, 85, 85)][font=宋体, "]
[color=rgb(85, 85, 85)][font=宋体, "]4、/etc/resolv.conf[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em][size=1em]; generated by /sbin/dhclient-script
[size=1em]nameserver 192.168.188.101
[size=1em]nameserver 114.114.114.114
[color=rgb(85, 85, 85)][color=rgb(85, 85, 85)][font=宋体, "]这是我虚拟机上的这个文件的内容,这个文件用于指定域名解析的DNS服务器ip地址等信息,配置参数一般有4个:[color=rgb(85, 85, 85)][font=宋体, "]nameserver #指定DNS服务器的IP地址[color=rgb(85, 85, 85)][font=宋体, "]domain #定义本地域名信息[color=rgb(85, 85, 85)][font=宋体, "]search #定义域名的搜索列表[color=rgb(85, 85, 85)][font=宋体, "]sortlist #对gethostbyname返回的地址进行排序[color=rgb(85, 85, 85)][font=宋体, "]最常用的是nameserver这个参数,其他的一般都不指定。[color=rgb(85, 85, 85)][font=宋体, "]
[color=rgb(85, 85, 85)][font=宋体, "]5、/etc/sysconfig/network[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em][size=1em][xiaoxiao@xiaoxiao ~]$ cat /etc/sysconfig/network
[size=1em]NETWORKING=yes
[size=1em]NETWORKING_IPV6=no
[size=1em]HOSTNAME=xiaoxiao
[size=1em]GATEWAY=192.168.0.1
[indent]典型配置如上,参数说明:[p=21, null, left]NETWORKING #设置网络是否有效[p=21, null, left]NETWORKING_IPV6 #IPV6网络是否有效[p=21, null, left]HOSTNAME #设置主机名,最好和/etc/hosts文件中的设置一样[p=21, null, left]GATEWAY #指定默认网关
[p=21, null, left]网络管理相关的工具:[p=21, null, left]ping:send ICMP ECHO_REQUEST to network hosts(man中的解释)[p=21, null, left]ping [option]... IP[p=21, null, left]-c #: 报文的个数[p=21, null, left]-W timeout: 等待响应报文的超时时长;[/indent][color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em]9
[align=right][size=1em][size=1em][root@xiaoxiao ~]# ping www.baidu.com -c 3 -W 3
[size=1em]PING www.a.shifen.com (180.97.33.108) 56(84) bytes of data.
[size=1em]64 bytes from 180.97.33.108: icmp_seq=1 ttl=128 time=12.1 ms
[size=1em]64 bytes from 180.97.33.108: icmp_seq=2 ttl=128 time=11.6 ms
[size=1em]64 bytes from 180.97.33.108: icmp_seq=3 ttl=128 time=11.2 ms
[size=1em]
[size=1em]--- www.a.shifen.com ping statistics ---
[size=1em]3 packets transmitted, 3 received, 0% packet loss, time 2015ms
[size=1em]rtt min/avg/max/mdev = 11.289/11.699/12.184/0.369 ms
[color=rgb(85, 85, 85)][font=宋体, "]traceroute:[indent]traceroute HOST获取当前主机到达目标主机所经过的所有网关[/indent][color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em][size=1em][xiaoxiao@xiaoxiao ~]$ traceroute baidu.com
[size=1em]traceroute to baidu.com (123.125.114.144), 30 hops max, 60 byte packets
[size=1em] 1 192.168.0.1 (192.168.0.1) 0.969 ms 1.574 ms 0.945 ms
[size=1em] 2 192.168.188.1 (192.168.188.1) 72.099 ms 71.877 ms 71.171 ms
[size=1em] 3 * * *
[size=1em] 4 * * *
[size=1em] 5 * * *
[size=1em]...........
[color=rgb(85, 85, 85)][font=宋体, "]netstat:查看网络状态信息[indent][indent][font=微软雅黑, "]-t #tcp协议相关的连接[/indent][indent][font=微软雅黑, "]-u #udp协议相关的连接[/indent][indent][font=微软雅黑, "]-n #显示数字格式的地址[/indent][indent][font=微软雅黑, "]-l #listen,显示处于监听状态的连接[/indent][indent][font=微软雅黑, "]-a # 所有状态的连接(包括已建立连接和监听的连接)[/indent][indent][font=微软雅黑, "]-p #显示会话中的进程程序名及进程号[/indent][indent]-r #routing,显示路由表使用方式如下:[/indent][/indent][color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em]9
[align=right][size=1em]10
[align=right][size=1em]11
[align=right][size=1em][size=1em][xiaoxiao@xiaoxiao ~]$ netstat -tunl
[size=1em]Active Internet connections (only servers)
[size=1em]Proto Recv-Q Send-Q Local Address Foreign Address State
[size=1em]tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
[size=1em]tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
[size=1em]tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
[size=1em]tcp 0 0 :::22 :::* LISTEN
[size=1em]tcp 0 0 ::1:631 :::* LISTEN
[size=1em]tcp 0 0 ::1:25 :::* LISTEN
[size=1em]udp 0 0 0.0.0.0:68 0.0.0.0:*
[size=1em]udp 0 0 0.0.0.0:631 0.0.0.0:*
[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em]9
[align=right][size=1em]10
[align=right][size=1em]11
[align=right][size=1em][size=1em][xiaoxiao@xiaoxiao ~]$ netstat -tan
[size=1em]Active Internet connections (servers and established)
[size=1em]Proto Recv-Q Send-Q Local Address Foreign Address State
[size=1em]tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
[size=1em]tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
[size=1em]tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
[size=1em]tcp 0 52 192.168.0.152:22 192.168.0.105:2986 ESTABLISHED
[size=1em]tcp 0 0 192.168.0.152:22 192.168.0.60:52684 ESTABLISHED
[size=1em]tcp 0 0 :::22 :::* LISTEN
[size=1em]tcp 0 0 ::1:631 :::* LISTEN
[size=1em]tcp 0 0 ::1:25 :::* LISTEN
[color=rgb(85, 85, 85)][font=宋体, "]显示路由表(同route -n):[color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em][size=1em][xiaoxiao@xiaoxiao ~]$ netstat -nr
[size=1em]Kernel IP routing table
[size=1em]Destination Gateway Genmask Flags MSS Window irtt Iface
[size=1em]192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[size=1em]169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
[size=1em]0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
[color=rgb(85, 85, 85)][indent][indent]注意:这里的State一般有两种状态:connected(established)和listen,若选项中没有-l,则显示connected状态的进程,若加上则显示处于监听状态的进程ss:查看网络状态信息这个命令用法与netstat相似,但功能更加强大,具体用法可以参考netstat。这里只给出一个例子[/indent][/indent][color=#555555][font=宋体, "][font=Consolas, "][size=1em]
[tr=none ][align=right][align=right][size=1em]1
[align=right][size=1em]2
[align=right][size=1em]3
[align=right][size=1em]4
[align=right][size=1em]5
[align=right][size=1em]6
[align=right][size=1em]7
[align=right][size=1em]8
[align=right][size=1em]9
[align=right][size=1em]10
[align=right][size=1em][size=1em][xiaoxiao@lwg ~]$ ss -tunl
[size=1em]Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
[size=1em]udp UNCONN 0 0 *:68 *:*
[size=1em]udp UNCONN 0 0 *:631 *:*
[size=1em]tcp LISTEN 0 128 :::22 :::*
[size=1em]tcp LISTEN 0 128 *:22 *:*
[size=1em]tcp LISTEN 0 128 127.0.0.1:631 *:*
[size=1em]tcp LISTEN 0 128 ::1:631 :::*
[size=1em]tcp LISTEN 0 100 ::1:25 :::*
[size=1em]tcp LISTEN 0 100 127.0.0.1:25 *:*