Linux就业技术指导(五):Linux运维核心管理命令详解 (12)

思考
我们该如何用ip命令创建网卡的别名IP呢?

[root@Mr_chen ~]# ip a add 192.168.0.225/24 dev eth1 label eth1:1 #使用label选项创建别名IP [root@Mr_chen ~]# ip a show eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a8:ca:5f brd ff:ff:ff:ff:ff:ff inet 192.168.0.222/24 scope global eth1 #eth1网卡的主IP inet 192.168.0.223/24 scope global secondary eth1 #eth1网卡的辅助IP inet 192.168.0.225/24 scope global secondary eth1:1 #eth1网卡的别名IP inet6 fe80::20c:29ff:fea8:ca5f/64 scope link valid_lft forever preferred_lft forever

知识扩展:
我们利用ifconfig命令只能查看到网卡的别名IP而看不到它的辅助IP

[root@Mr_chen ~]# ip a show eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a8:ca:5f brd ff:ff:ff:ff:ff:ff inet 192.168.0.222/24 scope global eth1 inet 192.168.0.223/24 scope global secondary eth1 #辅助IP inet 192.168.0.225/24 scope global secondary eth1:1 #别名IP inet6 fe80::20c:29ff:fea8:ca5f/64 scope link valid_lft forever preferred_lft forever [root@Mr_chen ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:A8:CA:50 inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fea8:ca50/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5857 errors:0 dropped:0 overruns:0 frame:0 TX packets:1019 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:420049 (410.2 KiB) TX bytes:119175 (116.3 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:A8:CA:5F inet addr:192.168.0.222 Bcast:0.0.0.0 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fea8:ca5f/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:32 errors:0 dropped:0 overruns:0 frame:0 TX packets:12 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4212 (4.1 KiB) TX bytes:936 (936.0 b) eth1:1 Link encap:Ethernet HWaddr 00:0C:29:A8:CA:5F #别名IP inet addr:192.168.0.225 Bcast:0.0.0.0 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

(6)查看路由表

[root@Mr_chen ~]# ip route 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.100 192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.222 169.254.0.0/16 dev eth0 scope link metric 1002 default via 192.168.0.1 dev eth0 [root@Mr_chen ~]# ip route | column -t #使用column命令格式化,选项-t,默认根据空格分隔判断输入行的列数来创建一个表 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.100 192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.222 169.254.0.0/16 dev eth0 scope link metric 1002 default via 192.168.0.1 dev eth0 [root@Mr_chen ~]# route -n #与我们前面学习过的route命令对比一下 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0

(7)添加或删除路由表

[root@Mr_chen ~]# ip route add 192.168.1.0/24 via 192.168.0.254 dev eth1 #添加静态路由 [root@Mr_chen ~]# ip route | column -t 192.168.1.0/24 via 192.168.0.254 dev eth1 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.100 192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.222 169.254.0.0/16 dev eth0 scope link metric 1002 default via 192.168.0.1 dev eth0 [root@Mr_chen ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 192.168.0.254 255.255.255.0 UG 0 0 0 eth1 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0 [root@Mr_chen ~]# ip route del 192.168.1.0/24 #删除静态路由 [root@Mr_chen ~]# ip route | column -t 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.100 192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.222 169.254.0.0/16 dev eth0 scope link metric 1002 default via 192.168.0.1 dev eth0 2.2 netstat:查看网络状态 2.2.1 命令详解

功能说明:

netstat命令用于显示本机网络的连接状态,运行端口和路由表等信息。

选项说明:

参数选项 解释说明(带@的为重点)
-r   显示路由表信息,该功能类似与前面学过的route和ip route  
-g   显示多播功能群组成员,该功能类似于前面学过的ip maddr  
-i   显示网络接口信息,该功能类似于前面学过的ip -s link  
-s   显示各类协议的统计信息  
-n   显示数字形式的地址而不是去解析主机,端口或用户名。默认情况下,netstat命令会尝试解析并显示主机的主机名,这个过程通常比较长也是非必需的@  
-a   显示处于监听状态和非监听状态的socket信息@  
-A   显示指定网络类型的网络连接状态  
-c<秒数>   后面跟的秒数表示每隔几秒就刷新显示一次@  
-l   仅显示连接状态为“LISTEN”的服务的网络状态  
-t   显示所有的TCP连接情况@  
-u   显示所有的UDP连接情况@  
-p   显示socket所属进程的PID和名称@  
2.2.2 使用范例 基础范例

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zygwxj.html