CentOS 7中网络设置图文详解

查看CentOS 7网络接口信息

查看所有活动网络接口的信息

ifconfig命令

[root@localhost ~]# ifconfig //查看网络接口信息 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 6139 bytes 3599390 (3.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2483 bytes 330519 (322.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 1 (Local Loopback) RX packets 84 bytes 7500 (7.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 84 bytes 7500 (7.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:d9:de:d2 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

查看指定网络接口信息

ifconfig 网络接口

[root@localhost ~]# ifconfig ens33 //查看ens33网络接口信息 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 6183 bytes 3602858 (3.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2505 bytes 334073 (326.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 查看主机名称

查看或设置当前主机名

hostname命令

[root@localhost ~]# hostname //查看主机名称 localhost.localdomain

更改主机名称

hostnamectl set-hostname [主机名称]

[root@localhost ~]# hostnamectl set-hostname http01 //更改主机名 [root@localhost ~]# su //切换用户,刷新主机名 [root@http01 ~]# hostname //查看主机名称 http01 查看路由表条目

查看路由表

route命令

[root@http01 ~]# route //查看路由表 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 查看网络连接情况

查看系统的网络连接状态、路由表、接口统计等信息

netstat命令

netstat [选项]

常用选项

-a :全部

-n:数字格式显示

-p:协议

-t :tcp

-u :udp

-r:路由

[root@http01 ~]# netstat -antp //查看以数字格式显示全部TCP协议端口的网络连接情况 Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1308/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 983/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 985/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1292/master tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 4840/sshd: root@pts tcp 0 0 192.168.144.133:22 192.168.144.1:54734 ESTABLISHED 4840/sshd: root@pts tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::80 :::* LISTEN 2373/httpd tcp6 0 0 :::22 :::* LISTEN 983/sshd tcp6 0 0 ::1:631 :::* LISTEN 985/cupsd tcp6 0 0 ::1:25 :::* LISTEN 1292/master tcp6 0 0 ::1:6010 :::* LISTEN 4840/sshd: root@pts [root@http01 ~]# netstat -nuap //查看以数字格式显示全部UDP协议端口的网络连接情况 Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 0 0 0.0.0.0:36571 0.0.0.0:* 788/dhclient udp 0 0 0.0.0.0:47956 0.0.0.0:* 578/avahi-daemon: r udp 0 0 192.168.122.1:53 0.0.0.0:* 1308/dnsmasq udp 0 0 0.0.0.0:67 0.0.0.0:* 1308/dnsmasq udp 0 0 0.0.0.0:68 0.0.0.0:* 788/dhclient udp 0 0 0.0.0.0:5353 0.0.0.0:* 578/avahi-daemon: r udp 0 0 127.0.0.1:323 0.0.0.0:* 636/chronyd udp6 0 0 :::57996 :::* 788/dhclient udp6 0 0 ::1:323 :::* 636/chronyd [root@http01 ~]# netstat -r //查看路由信息,与route命令作用相同 Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface default gateway 0.0.0.0 UG 0 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 网络测试连接

测试网络通讯性

ping命令

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

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