11.3 IP command 11.3.1 IP to see which rpm the IP was generated from
[[email protected] ~]# rpm -qf `which ip`iproute-2.6.32-32.el6_5.i686
View Iproute-generated files
[[email protected] ~]# rpm-ql iproute/etc/iproute2/etc/iproute2/ematch_map/etc/iproute2/rt_dsfield/etc/ iproute2/rt_protos/etc/iproute2/rt_realms/etc/iproute2/rt_scopes/etc/iproute2/rt_tables/etc/sysconfig/cbq/etc/ Sysconfig/cbq/avpkt/etc/sysconfig/cbq/cbq-0000.example/sbin/bridge/sbin/cbq/sbin/ifcfg/sbin/ip/sbin/rtmon/sbin /tc/usr/lib/tc/usr/lib/tc/m_xt.so/usr/sbin/arpd/usr/sbin/lnstat/usr/sbin/nstat/usr/sbin/rtacct/usr/sbin/ss/usr /share/doc/iproute-2.6.32/usr/share/doc/iproute-2.6.32/copying/usr/share/doc/iproute-2.6.32/readme/usr/share/ doc/iproute-2.6.32/readme.decnet/usr/share/doc/iproute-2.6.32/readme.distribution/usr/share/doc/iproute-2.6.32 /readme.iproute2+tc/usr/share/doc/iproute-2.6.32/readme.lnstat/usr/share/man/man8/arpd.8.gz/usr/share/man/man8 /bridge.8.gz/usr/share/man/man8/cbq.8.gz/usr/share/man/man8/ifcfg.8.gz/usr/share/man/man8/ip.8.gz/usr/share/ man/man8/lnstat.8.gz/usr/share/man/man8/nstat.8.gz/usr/share/man/man8/routel.8.gz/usr/share/man/man8/ rtacct.8.gz/usr/share/man/man8/rtmon.8.gz/usr/share/man/man8/ss.8.gz/usr/share/man/man8/tc-bfifo.8.gz/usr/share/man/man8/ tc-cbq-details.8.gz/usr/share/man/man8/tc-cbq.8.gz/usr/share/man/man8/tc-htb.8.gz/usr/share/man/man8/ tc-pfifo.8.gz/usr/share/man/man8/tc-pfifo_fast.8.gz/usr/share/man/man8/tc-prio.8.gz/usr/share/man/man8/ Tc-red.8.gz/usr/share/man/man8/tc-sfq.8.gz/usr/share/man/man8/tc-tbf.8.gz/usr/share/man/man8/tc.8.gz/usr/share /tc/usr/share/tc/normal.dist/usr/share/tc/pareto.dist/usr/share/tc/paretonormal.dist
11.3.2 ip-link View All interface properties
[[email protected] ~]# ip link show1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:002: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link/ether 00:0c:29:a7:7a:ec brd ff:ff:ff:ff:ff:ff
View specified interface properties
[[email protected] ~]# ip link show ens332: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link/ether 00:0c:29:a7:7a:ec brd ff:ff:ff:ff:ff:ff
Close interface
[[email protected] ~]# ip link set dev lo down[[email protected] ~]# ip lin show lo1: lo: <LOOPBACK> mtu 65536 qdisc noqueue state DOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
Open Interface
[[email protected] ~]# ip link set dev lo up[[email protected] ~]# ip lin show lo1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
11.3.2 ip-addr Display all interface IP
[[email protected] ~]# ip addr show1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a7:7a:ec brd ff:ff:ff:ff:ff:ff inet 10.201.106.130/24 brd 10.201.106.255 scope global dynamic ens33 valid_lft 1018sec preferred_lft 1018sec inet6 fe80::20c:29ff:fea7:7aec/64 scope link valid_lft forever preferred_lft forever
Add an address, two addresses
[[email protected] ~]# ip addr add 10.201.106.119 dev ens33[[email protected] ~]# [[email protected] ~]# [[email protected] ~]# ip addr show dev ens332: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a7:7a:ec brd ff:ff:ff:ff:ff:ff inet 10.201.106.130/24 brd 10.201.106.255 scope global dynamic ens33 valid_lft 1654sec preferred_lft 1654sec inet 10.201.106.119/32 scope global ens33 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fea7:7aec/64 scope link valid_lft forever preferred_lft forever
Remove IP Address
[[email protected] ~]# ip addr delete 10.201.106.119/32 dev ens33[[email protected] ~]# ip addr show ens332: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a7:7a:ec brd ff:ff:ff:ff:ff:ff inet 10.201.106.130/24 brd 10.201.106.255 scope global dynamic ens33 valid_lft 1372sec preferred_lft 1372sec inet6 fe80::20c:29ff:fea7:7aec/64 scope link valid_lft forever preferred_lft forever
Add an IP address to the original base, adding a label
[[email protected] ~]# ip addr add 10.201.106.222/24 dev ens33 label ‘ens33:1‘[[email protected] ~]# ip add show ens332: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a7:7a:ec brd ff:ff:ff:ff:ff:ff inet 10.201.106.130/24 brd 10.201.106.255 scope global dynamic ens33 valid_lft 1151sec preferred_lft 1151sec inet 10.201.106.222/24 scope global secondary ens33:1 #显示label valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fea7:7aec/64 scope link valid_lft forever preferred_lft forever
Remove IP with label parameter
[[email protected] ~]# ip addr del 10.201.106.222/24 dev ens33 label ens33:1[[email protected] ~]# ip addr show ens332: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a7:7a:ec brd ff:ff:ff:ff:ff:ff inet 10.201.106.130/24 brd 10.201.106.255 scope global dynamic ens33 valid_lft 1482sec preferred_lft 1482sec inet6 fe80::20c:29ff:fea7:7aec/64 scope link valid_lft forever preferred_lft forever
Show only primary addresses
[[email protected] ~]# IP addr Show dev ens33 2:ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc Pfifo_ Fast state up Qlen link/ether 00:0c:29:a7:7a:ec brd ff:ff:ff:ff:ff:ff inet 10.201.106.130/24 BRD 10.201.106.255 Scope Global Dynamic Ens33 valid_lft 1183sec preferred_lft 1183sec inet 10.201.106.222/24 Scope Global Secondary Ens33:3 Valid_lft Forever Preferred_lft forever inet6 fe80::20c:29ff:fea7:7aec/64 scope link valid_lft fo Rever preferred_lft forever[[email protected] ~]# [[email protected] ~]# [[email protected] ~]# IP Addr Show Dev Ens33 primary2:ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc Pfifo_fast State up Qlen-Li Nk/ether 00:0c:29:a7:7a:ec BRD ff:ff:ff:ff:ff:ff inet 10.201.106.130/24 BRD 10.201.106.255 scope Global Dynamic ENS33 Valid_lft 1181sec preferred_lft 1181sec inet6 fe80::20c:29ff:fea7:7aec/64 scope link Valid_lft forever pref Erred_lft FOREVER[[EMAIL&NBSp;protected] ~]#
Show only secondary addresses
[[email protected] ~]# ip addr show dev ens33 secondary2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a7:7a:ec brd ff:ff:ff:ff:ff:ff inet 10.201.106.222/24 scope global secondary ens33:3 valid_lft forever preferred_lft forever
Clear IP Address according to label
[[email protected] ~]# ip addr flush dev ens33 label ens33:3[[email protected] ~]# ip addr show dev ens332: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a7:7a:ec brd ff:ff:ff:ff:ff:ff inet 10.201.106.130/24 brd 10.201.106.255 scope global dynamic ens33 valid_lft 1718sec preferred_lft 1718sec inet6 fe80::20c:29ff:fea7:7aec/64 scope link valid_lft forever preferred_lft forever
11.3.3 IP route Add host route
[[email protected] ~]# ip route add 192.168.1.3/32 via 10.201.106.2 dev ens33[[email protected] ~]# ip route showdefault via 10.201.106.2 dev ens33 proto static metric 100 10.201.106.0/24 dev ens33 proto kernel scope link src 10.201.106.130 metric 100 192.168.1.3 via 10.201.106.2 dev ens33
Add Network Segment Routing
[[email protected] ~]# ip route add 192.168.0.0/24 via 10.201.106.2 dev ens33[[email protected] ~]# ip route show dev ens33default via 10.201.106.2 proto static metric 100 10.201.106.0/24 proto kernel scope link src 10.201.106.130
Delete route
[[email protected] ~]# ip route del 192.168.1.3[[email protected] ~]# ip route listdefault via 10.201.106.2 dev ens33 proto static metric 100 10.201.106.0/24 dev ens33 proto kernel scope link src 10.201.106.130 metric 100 192.168.0.0/24 via 10.201.106.2 dev ens33 [[email protected] ~]# ip route del 192.168.0.0/24[[email protected] ~]# ip route listdefault via 10.201.106.2 dev ens33 proto static metric 100 10.201.106.0/24 dev ens33 proto kernel scope link src 10.201.106.130
Add a default route
[[email protected] ~]# ip route add default via 10.201.106.102[[email protected] ~]# route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 10.201.106.102 0.0.0.0 UG 0 0 0 ens330.0.0.0 10.201.106.2 0.0.0.0 UG 100 0 0 ens3310.201.106.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
Clear all routing tables
ip route flush
11.3.4 SS Displays all TCP processes, displayed as port numbers
[[email protected] ~]# ss -tanState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* ESTAB 0 0 10.201.106.130:22 10.201.106.1:49530 ESTAB 0 0 10.201.106.130:22 10.201.106.1:49506 LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25
Displays the connected state of the TCP connection
[[email protected] ~]# ss -tan state ESTABLISHEDRecv-Q Send-Q Local Address:Port Peer Address:Port 0 52 10.201.106.130:22 10.201.106.1:49530 0 0 10.201.106.130:22 10.201.106.1:49506
Configuration file configuration Network Ifcfg-eth0 configuration
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0# If you‘re having problems with gated making 127.0.0.0/8 a martian,# you can change this to something else (255.255.255.255, for example)ONBOOT="yes"TYPE="Ethernet"NM_CONTROLLED="yes"BOOTPROTO="static"IPADDR=10.201.106.250NETMASK=255.255.255.0GATEWAY=10.201.106.2
Configuration file Configuration Routing entry (1)
[[email protected] network-scripts]# vim route-eth0 192.168.0.0/24 via 10.201.106.2[[email protected] network-scripts]# route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface10.201.106.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0192.168.0.0 10.201.106.2 255.255.255.0 UG 0 0 0 eth0169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth00.0.0.0 10.201.106.2 0.0.0.0 UG 0 0 0 eth0
Configuration file Configuration Routing entry (2)
[[email protected] network-scripts]# vim route-eth0 address0=192.168.20.0netmask0=255.255.255.0gateway0= 10.201.106.2address1=192.168.30.0netmask1=255.255.255.0gateway1=10.201.106.2[[email protected] network-scripts]# Service network restartshutting down interface eth0: [OK]shutting down Loopback interface: [OK]bringing up loopback interface: [OK]BR Inging up Interface eth0:determining IP information for eth0 ... Done.ipcalc:bad IPv4 address:192.168.3330.0error:an i NET prefix is expected rather than "192.168.3330.0/24". [OK] [[email protected] network-scripts]# vim route-eth0 [[email protected] network-scripts]# service Network Restartshutting down interface eth0: [OK]shutting down Loopback interface: [OK] Bringing Up loopback interface: [OK] Bringing up interface eth0:determining IP information for eth0 ... done. [OK] [[email protected] network-scripts]# [[email protected] network-scripts]# [[email protected] network-scripts]# [[email protected] network-scripts]# route-nkernel IP routing tabledestination Gateway Genmask Flags Metric Ref use Iface192.168.20.0 10.201.106.2 255.255.255.0 UG 0 0 0 eth0 10.201.106.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0192.168.30.0 10.201.106.2 255.255.255.0 UG 0 0 0 eth0169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth00.0.0.0 10.201.106.2 0.0.0.0 UG 0 0 0 eth0
Ifcfg Configuring multiple Addresses
[[email protected] network-scripts]# ifconfig eth0:1 192.168.0.22/24 up[[email protected] network-scripts] # ifconfig eth0 Link encap:ethernet HWaddr 00:0c:29:4e:af:24 inet addr:10.201.106.128 bcast:10.201.106.2 mask:255.255.255.0 Inet6 addr:fe80::20c:29ff:fe4e:af24/64 scope:link up broadcast RUNNING multicast mtu:1500 metric:1 RX packets:2221 errors:0 dropped:0 overruns:0 frame:0 TX packets:1851 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:204895 (2 00.0 KiB) TX bytes:278337 (271.8 KiB) eth0:1 Link encap:ethernet HWaddr 00:0c:29:4e:af:24 inet addr:192.168 .0.22 bcast:192.168.0.255 mask:255.255.255.0 up broadcast RUNNING multicast mtu:1500 Metric:1lo Link E Ncap:local Loopback inet addr:127.0.0.1 mask:255.0.0.0 inet6 addr::: 1/128 scope:host up LOO Pback RUNNING mtu:65536 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) [[email protected] network-scripts]# [[email protected] network-scripts]# ping 192.168.0.22 ping 192.168. 0.22 (192.168.0.22) bytes of data. Bytes from 192.168.0.22:icmp_seq=1 ttl=64 time=1.05 ms to bytes from 192.168.0.22:icmp_seq=2 ttl=64 time=0.339 ms
Configuration file add alias card address
cp ifcfg-eth0 ifcfg-eth0:1[[email protected] network-scripts]# vim ifcfg-eth0:1DEVICE=eth0:1HWADDR=00:0C:29:4E:AF:24TYPE=EthernetUUID=a493b909-229d-4a02-b1b5-ebbb51d16983ONBOOT=yesNM_CONTROLLED=yesBOOTPROTO="static"IPADDR=192.168.0.22NETMASK=255.255.255.0DNS1=10.201.106.2
Tuisetup Call network configuration to change host name
[[email protected] network-scripts]# vim /etc/sysconfig/networkNETWORKING=yes #网络总开关,网络不通先确认该项有没打开HOSTNAME=zabbix.localdomain
Change Eth0 to Eth1
[[email protected] ~]# cd/etc/udev/rules.d/vim 70-persistent-net.rulessubsystem== "NET", ACTION== " Add ", drivers=="? * ", attr{address}==" 00:0c:29:4e:af:24 ", attr{type}==" 1 ", kernel==" eth* ", name=" eth1 #改为eth1 [[email& Nbsp;protected] rules.d]# lsmod #查看网卡 [[email protected] rules.d]# modprobe-r e1000 #卸载网卡 [[EMAIL&NB Sp;protected] rules.d]# modprobe e1000 #加载网卡 [[email protected] ~]# service Network restart #重启网络服务 [[EMAIL&NB Sp;protected] ~]# ifconfig-aeth1 Link encap:ethernet HWaddr 00:0c:29:4e:af:24 inet addr:10.201.106.128 bcast:10.201.106.255 mask:255.255.255.0 inet6 addr:fe80::20c:29ff:fe4e:af24/64 scope:link up BROADCAST RUNNING multicast mtu:1500 metric:1 RX packets:350 errors:0 dropped:0 overruns:0 frame:0 TX packets:305 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:34875 (34. 0 KiB) TX bytes:65070 (63.5 KiB)
Linux-ip Command Miscellaneous