Linux Basics - Network management of the network interface (NIC) management
- First, network management
First, network management
1. Network Status View: ip addr (ifconfig)
1.1 net-tools (centos 7 previous version) VS iproute2 (Centos recommended after 7)
1.1.1 net-tools (centos 7 previous version)
-
ifconfig # Network Interface Management Command
network interface naming conventions: CentOS 7 uses a consistent network device namingNetwork Interface Name NIC type en01
Onboard LAN ens33
PCI-E card enp0s3
Unable to get a physical card PCI-E card eth0
In addition to these card types
Example:
`查看所有接口信息`
[root@localhost ~]# ifconfig -a
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.5.128 netmask 255.255.255.0 broadcast 192.168.5.255
inet6 fe80::20c:29ff:fe12:dd9c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:12:dd:9c txqueuelen 1000 (Ethernet)
RX packets 373 bytes 35292 (34.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 322 bytes 48941 (47.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 140 bytes 14788 (14.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 140 bytes 14788 (14.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
"网络接口启用/停用":'使用远程终端连接小心停用网络接口'
[root@localhost ~]# ifconfig [dev-name] [up|down]
dev-name :网络接口名称,如,ens32
-
route # route setting commands
route
commands by default IP resolves domain name or service name, so the speed will be very slow, useroute -n
can not resolve domain names, speed up response time; as follows:
[root@localhost ~]# time route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 100 0 0 eth0 192.168.5.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 real 0m0.010s user 0m0.000s sys 0m0.008s [root@localhost ~]# time route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.5.2 0.0.0.0 UG 100 0 0 eth0 192.168.5.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 real 0m0.003s user 0m0.000s sys 0m0.004s
-
netstat # Network Socket View
1.1.2 iproute2 (Centos 7 after the recommendation, superior net-tools)
- ip See: Linux foundation of basic network ip command
- ss See: Linux foundation of basic network command ss
1.1.3 Network Interface name changed toeth0
To modify a network interface commands ideas:
-
NIC naming and net.ifnames parameter limits by biosdevname
-
Modifying
/etc/default/grub
the file, add the above parameters (biosdevname = 0 net.ifnames = 0) , as follows:
-
Use
grub
file rebuild/boot/grub2/grub.cfg
boot files, file location note grub.cfg[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-b21899b2f3ce4b5c8d131cd0cb02811f Found initrd image: /boot/initramfs-0-rescue-b21899b2f3ce4b5c8d131cd0cb02811f.img done
-
Restart to take effect
reboot
-
NIC view the modified name
[root@localhost ~]# ifconfig `eth0`: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.5.128 netmask 255.255.255.0 broadcast 192.168.5.255 inet6 fe80::f43f:e585:bceb:5680 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:12:dd:9c txqueuelen 1000 (Ethernet) RX packets 50 bytes 6690 (6.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 67 bytes 11488 (11.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Schedule: biosdevname and net.ifnames parameters:
Name card biosname net.ifnames ens33
(default)0 0 em1
1 0 eth0
0 0 Note: Some Tips modify the network card with file NAME parameter is
eth0
not required and only need to add biosdevname net.ifnames parameters can be configured for this purpose in the grub
1.1.4 View Card physical connection (ie 网线连接状态
):mii-tool
2. Network configuration: / etc / sysconfig / network-script /
2.1 modify the network card configuration
- ifconfig <Interface Interface> <IP address> [netmask] # modify IP network interface
- ifup <Interface Interface> # Enable Network Interface
- ifdown <Interface Interface> # Disable Network Interface
2.2 network control command: ip
Command VS ss
command
- ip addr # View card information
- ifconfig
- ip link set dev eth0 up # Enable NIC
- ifup eth0
- ip addr add 192.168.5.130/24 dev eth0 # add an address to the network card
- ifconfig eth0 192.168.5.130 netmask 255.255.255.0
- ip route add 192.168.6 / 24 via 192.168.0.1 # added Gateway
- route add -net 192.168.6.0 netmask 255.255.255.0 gw 192.168.0.1
3. Route command: ip route
View the routing information:
[root@localhost ~]# ip route show|column -t
default via 192.168.5.2 dev eth0
default via 192.168.5.2 dev eth0 proto dhcp metric 100
192.168.5.0/24 dev eth0 proto kernel scope link src 192.168.5.128 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
4. Network troubleshooting
- Network connectivity ping #
- traceroute # routing status
- mtr # packet loss state
- DNS dig nslookup #
- tcpdump # crawl the web Package
- netstat # View application port status
- ss # View application port status ( recommended )
[root@localhost ~]# ss -ntpl |column -t State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* users:(("rpcbind",pid=6174,fd=4),("systemd",pid=1,fd=49)) LISTEN 0 5 192.168.122.1:53 *:* users:(("dnsmasq",pid=7165,fd=6)) LISTEN 0 128 *:22 *:* users:(("sshd",pid=6773,fd=3)) LISTEN 0 128 127.0.0.1:631 *:* users:(("cupsd",pid=6774,fd=12)) LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=7176,fd=13)) LISTEN 0 128 127.0.0.1:6010 *:* users:(("sshd",pid=6857,fd=9)) LISTEN 0 128 :::111 :::* users:(("rpcbind",pid=6174,fd=6),("systemd",pid=1,fd=51)) LISTEN 0 128 :::22 :::* users:(("sshd",pid=6773,fd=4)) LISTEN 0 128 ::1:631 :::* users:(("cupsd",pid=6774,fd=11)) LISTEN 0 100 ::1:25 :::* users:(("master",pid=7176,fd=14)) LISTEN 0 128 ::1:6010 :::* users:(("sshd",pid=6857,fd=8))