View network related commands
-
Yum install iproute2
-
Ifconfig Displays nic information. Yum install net-tools
A comparison of the two:
Linux’s IP command is similar to ifconfig, but the former is more powerful and is intended to replace the latter. Ifconfig is a deprecated command in Net-Tools that has not been maintained for many years. The IP command is one of the many enhanced commands available in the iproute2 suite.
ip a
View the interface information of all network adapters.
Here a is not an option but OBJECT: address.
[root@localhost ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 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 forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:d2:ca:67 brd Ff: FF: FF: FF: FF: FF: FF inet 172.16.230.224/24 BRD 172.16.230.255 Scope Global NoprefixRoute Dynamic ENS33 VALID_LFT 82828sec preferred_lft 82828sec inet6 fe80::4e92:349a:6f19:ff18/64 scope link noprefixroute valid_lft forever preferred_lft forever 3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:d2:ca:71 brd Ff: FF: FF: FF: FF: FF: FF INET 172.16.230.251/24 BRD 172.16.230.255 Scope Global NoprefixRoute Dynamic ENS37 VALID_LFT 82828sec preferred_lft 82828sec inet6 fe80::3eae:dcdd:5ed8:5736/64 scope link noprefixroute valid_lft forever preferred_lft foreverCopy the code
Points to be clear:
Lo is a virtual network interface in Linux
Used when different processes on the same machine communicate. Realized the socket communication between the processes of the same machine. Virtual network interfaces do not require drivers.
Link /ether is a layer 2 protocol
MAC address: 00:0C :29: D2: CA :67
Address :ff:ff:ff:ff:ff :ff
Inet (V4) is a layer 3 protocol
IP address: 172.16.230.224/24
Broadcast address: 172.16.230.255
Inet6 is a layer 3 protocol
Ipv6 address: fe80: : e92:349 a: 6 f19: ff18/64
ip -x a
Only ipvX-related information about the network interface is displayed
[root@Tyson Lee ~]# ip -6 a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 state UNKNOWN qlen 1 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000 inet6 fe80::4e92:349a:6f19:ff18/64 scope link noprefixroute valid_lft forever preferred_lft forever 3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000 inet6 fe80::3eae:dcdd:5ed8:5736/64 scope link noprefixroute valid_lft forever preferred_lft forever [root@localhost ~]# ip -4 a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: ens33: < BROADCAST, MULTICAST, UP, LOWER_UP > mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 172.16.230.224/24 BRD 172.16.230.255 scope global noprefixroute dynamic ens33 valid_lft 82486sec preferred_lft 82486sec 3: ens37: < BROADCAST, MULTICAST, UP, LOWER_UP > mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 172.16.230.251/24 BRD 172.16.230.255 scope global noprefixroute dynamic ens37 valid_lft 82486sec preferred_lft 82486secCopy the code
ip a show ens37
Displays information about a specified network adapter
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:d2:ca:71 brd Ff: FF: FF: FF: FF: FF: FF INET 172.16.230.251/24 BRD 172.16.230.255 Scope Global NoprefixRoute Dynamic ENS37 VALID_LFT 82450sec preferred_lft 82450sec inet6 fe80::3eae:dcdd:5ed8:5736/64 scope link noprefixroute valid_lft forever preferred_lft [root@localhost ~]# ifconfig ens37 Flags = 4163 < UP, BROADCAST, RUNNING, MULTICAST > mtu 1500 inet 172.16.230.251 netmask 255.255.255.0 BROADCAST 172.16.230.255 inet6 fe80::3eae:dcdd:5ed8:5736 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:d2:ca:71 txqueuelen 1000 (Ethernet) RX Packets 4648 bytes 454522 (443.8 KiB) RX errors 0 dropped 0 Overruns 0 frame 0 TX packets 15 bytes 1410 (1.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0Copy the code
ip -4 a show ens37
Displays ipv4 information about a specific interface
ip link ls up
View information about the running interface
IP Link LS Down (vice versa)
ip a list ens37
The result is the same as IP a show ENS37
Example Modify the network port (NIC) information
Card related
To configure a specific interface, that is, to assign an IP address to a network adapter. (An IP address and a mask are required.)
-
IP a (ddress) add 192.168.0.128/255.255.255.0 dev ens37
-
IP a(ddress) add 192.168.0.128/24 dev ens37
-
The ifconfig ens37 192.168.0.128/24
-
Ifconfig ens37 192.168.0.128 netmask 255.255.255.0
Deleting a Network interface (nic)
- IP a (ddress) del 192.168.0.129/255.255.255.0 dev ens37
However, if the IP address of the same network interface (nic) is repeatedly configured, the IP address will not be overwritten.
Therefore, you need to delete the previously configured IP address. (Or select one to delete)
Disabling or enabling a network interface (nic)
-
ip link set dev ens3 up
-
ip link set dev ens37 down
-
ifconfig ens37 down
-
ifconfig ens37 up
Set the transmission queue of the nic
ip link set txqueuelen 10000 dev ens37
[root@Tyson Lee ~]# ifconfig |grep -n "txqu"
4: ether 00:0c:29:d2:ca:67 txqueuelen 1000 (Ethernet)
13: ether 00:0c:29:d2:ca:71 txqueuelen 1000 (Ethernet)
22: loop txqueuelen 1 (Local Loopback)
[root@Tyson Lee ~]# ip link set txqueuelen 10000 dev ens37
[root@Tyson Lee ~]# ifconfig |grep -n "txqu"
4: ether 00:0c:29:d2:ca:67 txqueuelen 1000 (Ethernet)
13: ether 00:0c:29:d2:ca:71 txqueuelen 10000 (Ethernet)
22: loop txqueuelen 1 (Local Loopback)
[root@Tyson Lee ~]# ip link set txqueuelen 1000 dev ens37
Copy the code
Set the maximum transfer unit of the nic (default: 1500 bytes)
ip link set mtu 9000 dev ens37
[root@Tyson Lee ~]# ifconfig |grep -n "mtu" 1:ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 150010:ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 150019:lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
Copy the code
Jumbo frames:
Is an Ethernet frame larger than 1522 bytes. This is a vendor-standard ultra Long frame format designed specifically for Gigabit Ethernet. The size of jumbo frames varies by vendor, from 9000 to 64,000 bytes. Using jumbo frames can give full play to gigabit Ethernet performance and improve data transmission efficiency by 50% to 100%. In the application environment of network storage, giant frame has more extraordinary significance.
Routing table correlation
Adding a Default Gateway
IP route add 192.168.0.127 via 192.168.0.1 dev ens33
IP route add Destination network segment via Next hop DEV initial interface
Note that this cannot be set arbitrarily, the command will check whether the gateway is reachable or correct before taking effect.
Often, you also need to set a subnet mask
Such as:
A host has IP addresses of two carriers :(telecom)202.116.128.222/24, (unicom)100.10.10.10/24
B host has IP addresses of two carriers :(telecom)100.116.128.222/24, (unicom)200.20.20.10/24
When machines have multiple IP addresses and different ISPs, detailed routing is required.
On host A: IP route add default via 100.10.10.1. If this setting is set, host A still uses unicom’s gateway 100.10.10.1 to access the telecom network, which may cause high latency and packet loss.
In host A, run the IP route add 100.116.128.0 via 202.116.128.1 command. If this command is set, host A uses telecom’s gateway 202.116.128.1 when accessing telecom’s network.
Deleting the Default Gateway
IP route del 192.168.0.127 via 192.168.0.1 dev ens33
After the detailed route is deleted, the detailed route disappears.
[root@Tyson Lee ~]# IP route del 192.168.0.127 via 192.168.0.1 dev ens33 [root@Tyson Lee ~]# route -n Kernel IP routing Table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.0.1 0.0.0.0 UG 100 00 ENS33 0.0.0.0 192.168.0.1 0.0.0.0 UG 101 00 ENS37 192.168.0.0 0.0.0.0 255.255.255.0 U 100 00 ENS33 192.168.0.0 0.0.0.0 255.255.255.0 U 101 0 0 ens37Copy the code
Viewing the Routing Table
-
Route-n is friendlier
-
ip route show
Route-n {route-n}
Destination: indicates the Destination address
Gateway: default Gateway
Genmask: mask corresponding to the destination IP address (used to determine the most delicate next hop)
Flags: the tag
Metric: overhead
Use
Iface: indicates the initial interface of the next hop
Add or delete routes
IP route add 192.168.1.0/24 dev ens33
IP route del 192.168.1.0/24 dev ens33
Arp table related
Arp converts IP addresses to MAC addresses on a LAN. Because of the MAC address of the end-to-end communication in the LAN (layer 2 communication in the LAN).
# Linux [root@localhost ~]# IP neighbor show 172.16.230.233 dev ens33 lladdr 04:50:da:08:28:59 STALE 172.16.230.216 dev Ens33 llADDR 9C: 2E: A1:93: C8: C9 STALE 172.16.230.223 dev ens33 llADDR B8:81:98:65 :be:81 DELAY 172.16.230.1 dev ens33 Lladdr 00:12:7F :04:33:46 STALE 172.16.230.1 dev ENS37 llADDR 00:12:7F :04:33:46 STALE # Wireless LAN adapter for Windows in the same network segment WLAN: connect the specific DNS suffix........ :............... : Intel(R) Dual Band Wireless-AC 3165 Physical address............. : B8-81-98-65-BE-81 DHCP enabled........... : Automatic configuration is enabled.......... : IPv6 address is the local link........ : Cd5 fe80: : 1:52 f7:7452:3394% 4 (preferred) IPv4 addresses............ : 172.16.230.223 (preferred) subnet mask............ : 255.255.255.0 Time to obtain the lease......... : January 12, 2019 14:25:15 Time when the lease expires......... : On January 13, 2019 15:17:21 default gateway............. : 172.16.230.1 DHCP server........... : 172.16.230.1 DHCPv6 IAID........... : 62423448 DHCPv6 client DUID....... : 00-01-00-01-1-02-98 - F D9 - C8-5 b - 76-23 - D2-6 c DNS server........... : 114.114.114.114 NetBIOS on TCPIP....... : EnabledCopy the code
View arp table information
ip neighbor show
[root@Tyson Lee ~]# IP neighbor show 192.168.1.127 dev ens33 lladdr B8:27 :eb: C0: FA :23 STALE 192.168.0.103 dev ens33 Lladdr 78:67: D7:9C :19:85 STALE 192.168.0.1 dev ens33 lladdr F4 :83: CD :17:cb:49 DELAY 192.168.0.127 dev ens37 lladdr B8:27 :eb:c0: FA :23 STALE 192.168.0.109 dev ens33 lladdr b8:81:98:65:be:81 DELAYCopy the code
Yes Displays information about the IP address and MAC address in the ARP table cache.
Instead of sending a request broadcast asking for a MAC address.
View the ARP cache entry of a specific interface
ip neighbor show dev ens33
View arp cache entries on a specific network segment
IP neighbor show 192.168.0.0/24
[root@Tyson Lee ~]# IP neighbor show 192.168.0.0/24 192.168.0.127 dev ens33 lladdr B8:27 :eb: C0: FA :23 STALE 192.168.0.103 Dev ens33 lladdr 78:67: D7:9C :19:85 STALE 192.168.0.1 dev ens33 lladdr F4 :83: CD :17: CB :49 STALE 192.168.0.127 dev ens37 Lladdr B8:27 :eb: C0: FA :23 STALE 192.168.0.109 dev ens33 lladdr B8:81:98:65 :be:81 REACHABLECopy the code
Write a permanent other entry in the ARP cache
IP neighbor add 192.168.0.0/24 llADDR 00:c0:7d:00:c8 dev ens37 nud permanent
IP neighbor add 192.168.0.0/24 lladdr MAC address dev Whether the NUD of the corresponding interface is permanent
-
Note that the MAC address corresponding to the same destination network segment is not overwritten
-
Therefore, you need to delete or run the IP neighbor change command
-
Delete indicates that the CORRESPONDING MAC address is deleted but the IP address remains
Adding ARP Proxy
IP neighbor add proxy 192.168.0.1 dev ens37
Blog.51cto.com/chenxinjie/…
Arp refresh
If the cache is found to be contaminated or incorrect
ip neighbor flush dev ens33
Refresh the front:
[root@Tyson Lee ~]# IP neighbor show 192.168.1.127 dev ens33 lladdr B8:27 :eb: C0: FA :23 STALE 192.168.0.103 dev ens33 Lladdr 78:67: D7:9C :19:85 STALE 192.168.0.1 dev ens33 lladdr F4 :83: CD :17:cb:49 DELAY 192.168.0.127 dev ens37 lladdr B8:27 :eb:c0: FA :23 STALE 192.168.0.109 dev ens33 lladdr b8:81:98:65:be:81 DELAYCopy the code
After the refresh:
The MAC address is gone and needs to be relearned
[root@Tyson Lee ~]# IP neighbor show 192.168.0.127 dev ens33 FAILED 192.168.0.103 dev ens33 FAILED 192.168.0.1 dev ens33 FAILED 192.168.0.127 dev ens37 lladdr B8:27 :eb: C0: FA :23 STALE 192.168.0.109 dev ens33 lladdr B8:81:98:65 :be:81 REACHABLECopy the code
Reprinted from blog.csdn.net/chinaltx/ar…