三大家族轻松管理CentOS 7网络属性配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了三大家族轻松管理CentOS 7网络属性配置相关的知识,希望对你有一定的参考价值。
一、简单介绍
在CentOS 7中对网络管理还是有不少变化的,例如管理服务的命令变为systemctl,许多命令可以更改后直接生效,还有许多独有的工具,本文以CentOS 6与CentOS 7对比进行讲解,下面现总体介绍一下网络属性配置工具。
ifcfg家族
ifcofnig:配置IP,NETMASK
route:路由
netstat:状态及统计数据查看
iproute家族
ip OBJECT:
addr: 地址和掩码
link:接口
route:路由
ss:状态及统计数据查看
CentOS 7:nm(Network Manager)家族
nmcli:命令行工具
nmtui:text window工具
二、ifcfg家族配置管理
1、ifconfig命令:配置网络接口(configure a network interface)
查看网络配置:ifconfig [-a] [interface]
-a:查看当前系统上所有网络接口的状态及详细信息,包括inactive状态的接口
# ifconfig eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.18.250.108 netmask 255.255.0.0 broadcast 172.18.255.255 inet6 fe80::20c:29ff:fedd:c19c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:dd:c1:9c txqueuelen 1000 (Ethernet) RX packets 267796 bytes 27852817 (26.5 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4268 bytes 556507 (543.4 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 0 (Local Loopback) RX packets 56 bytes 4760 (4.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 56 bytes 4760 (4.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
CentOS 7:ifconfig命令显示参数详解
eno1677736:网卡名称
inet:ip地址
netmask:子网掩码
broadcast:广播地址
UP:网卡表示激活状态
BROADCAST:支持广播功能
MULTICAST:支持组播功能
RUNNING:处于运行状态
mtu:网卡的最大传输单元
inet6:表示IPV6地址
ether:以太网地址,表示mac地址
txqueuelen:传输队列长度
RX packets 267796 bytes 27852817 (26.5 MiB):接收到报文的数量,后面表示接 收到所有报文的大小
RX errors:接收到错误报文的个数
dropped:丢包的数量
overruns:溢出的
TX packets 4268 bytes 556507 (543.4 KiB):传出到报文的数量,后面表示传出所 有报文的大小
TX errors:传出报文的错误数量
dropped:发送出去丢包数量
此处为CentOS 6上使用ifconfig的显示(注意:不标明的都默认指CentOS7,当与CentOS不同时会标注)
# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:69:45:7B inet addr:172.18.251.87 Bcast:172.18.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fe69:457b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:303612 errors:0 dropped:0 overruns:0 frame:0 TX packets:2296 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:31934172 (30.4 MiB) TX bytes:261862 (255.7 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:69:45:85 inet addr:192.168.200.3 Bcast:192.168.200.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe69:4585/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:292609 errors:0 dropped:0 overruns:0 frame:0 TX packets:202 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:30767674 (29.3 MiB) TX bytes:26126 (25.5 KiB) 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: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)
CentOS 6:ifconfig命令显示参数详解
eth0:网卡名称
Link encap:接口类型
inet addr:ip地址
Bcast:广播地址
Mask:子网掩码
inet6 addr:IPV6地址
UP:网卡表示激活状态
BROADCAST:支持广播功能
MULTICAST:支持组播功能
RUNNING:处于运行状态
mtu:网卡的最大传输单元
ether:以太网地址,表示mac地址
txqueuelen:传输队列长度
RX packets 接收到报文的数量
errors:接收到错误报文的个数
dropped:丢包的数量
overruns:溢出的
TX packets 传出到报文的数量
errors:传出报文的错误数量
dropped:丢包的数量
overruns:溢出的
RX bytes: 接收到报文的总大小
TX bytes: 传输报文的总大小
# ifconfig -a eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.18.250.108 netmask 255.255.0.0 broadcast 172.18.255.255 inet6 fe80::20c:29ff:fedd:c19c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:dd:c1:9c txqueuelen 1000 (Ethernet) RX packets 267877 bytes 27861934 (26.5 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4283 bytes 559025 (545.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eno33554984: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether 00:0c:29:dd:c1:a6 txqueuelen 1000 (Ethernet) RX packets 257603 bytes 26825123 (25.5 MiB) RX errors 0 dropped 269 overruns 0 frame 0 TX packets 38 bytes 3900 (3.8 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 0 (Local Loopback) RX packets 56 bytes 4760 (4.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 56 bytes 4760 (4.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
可以指定接口名称,进行单独查看
# ifconfig eno33554984 eno33554984: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether 00:0c:29:dd:c1:a6 txqueuelen 1000 (Ethernet) RX packets 257603 bytes 26825123 (25.5 MiB) RX errors 0 dropped 269 overruns 0 frame 0 TX packets 38 bytes 3900 (3.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
修改网络配置:ifconfig [-v] interface [aftype] options | address ...
方式一:
# ifconfig eno33554984 192.168.200.5/24 up # ifconfig eno33554984 eno33554984: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.200.5 netmask 255.255.255.0 broadcast 192.168.200.255 ether 00:0c:29:dd:c1:a6 txqueuelen 1000 (Ethernet) RX packets 259004 bytes 26985088 (25.7 MiB) RX errors 0 dropped 271 overruns 0 frame 0 TX packets 40 bytes 4020 (3.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# 注意此配置仅限临时生效,重启网络服务或者重启系统,内核会重读配置文件,将配置文件中的参数在执行一遍.
方式二:
# ifconfig eno33554984 192.168.100.5 netmask 255.255.255.0 up # ifconfig eno33554984 eno33554984: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.100.5 netmask 255.255.255.0 broadcast 192.168.100.255 ether 00:0c:29:dd:c1:a6 txqueuelen 1000 (Ethernet) RX packets 260398 bytes 27138591 (25.8 MiB) RX errors 0 dropped 273 overruns 0 frame 0 TX packets 40 bytes 4020 (3.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、route命令:查看及管理路由(route - show / manipulate the IP routing table)
命令格式:route add [-net|-host] target [netmask Nm] [gw GW] [[dev] If]
-net:表示添加网络路由
-host:表示添加主机路由
gw:为默认网关
查看:
route -n
# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.18.0.1 0.0.0.0 UG 100 0 0 eno16777736 172.18.0.0 0.0.0.0 255.255.0.0 U 100 0 0 eno16777736 192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eno33554984
添加路由:
# route add -net 10.0.0.0/8 gw 192.168.100.5 dev eno33554984 # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.18.0.1 0.0.0.0 UG 100 0 0 eno16777736 10.0.0.0 192.168.100.5 255.0.0.0 UG 0 0 0 eno33554984 172.18.0.0 0.0.0.0 255.255.0.0 U 100 0 0 eno16777736 192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eno33554984
删除路由:
# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.18.0.1 0.0.0.0 UG 100 0 0 eno16777736 10.0.0.0 192.168.100.5 255.0.0.0 UG 0 0 0 eno33554984 172.18.0.0 0.0.0.0 255.255.0.0 U 100 0 0 eno16777736 192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eno33554984 # route del -net 10.0.0.0/8 # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.18.0.1 0.0.0.0 UG 100 0 0 eno16777736 172.18.0.0 0.0.0.0 255.255.0.0 U 100 0 0 eno16777736 192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eno33554984
3、netstat命令:打印网络连接,路由表,接口等信息(Print network connections, routing tables, interface statis﹖ics, masquerade connections, and multicast memberships)
显示网络连接:
netstat [--tcp|-t] [--udp|-u] [--udplite|-U] [--sctp|-S] [--raw|-w] [--listening|-l] [--all|-a] [--numeric|-n] [--extend|-e[--extend|-e]] [--program|-p]
-t:TCP协议的相关连接,连接均有其状态
-u:UDP协议相关的连接
-w:raw socket相关的;连接
-l:处于监听状态的连接
-a:所有状态
-n:以数字格式显示IP和Port
-e:扩展格式
-p:显示相关的进程及PID
# 常用组合:
-tan,-una,-tnl,-unl,-tunlp,-antup
# netstat -tan Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN tcp 0 52 172.18.250.108:22 172.18.4.1:49701 ESTABLISHED tcp 0 0 172.18.250.108:22 172.18.4.1:49924 ESTABLISHED tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:631 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN tcp6 0 0 ::1:6010 :::* LISTEN tcp6 0 0 ::1:6011 :::* LISTEN # netstat -uan Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State udp 0 0 0.0.0.0:10042 0.0.0.0:* udp 0 0 127.0.0.1:323 0.0.0.0:* udp 0 0 0.0.0.0:68 0.0.0.0:* udp6 0 0 ::1:323 :::* udp6 0 0 :::50626 :::* # netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1054/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1052/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1143/master tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 1190/sshd: [email protected] tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 5116/sshd: roo[email protected] tcp6 0 0 :::22 :::* LISTEN 1054/sshd tcp6 0 0 ::1:631 :::* LISTEN 1052/cupsd tcp6 0 0 ::1:25 :::* LISTEN 1143/master tcp6 0 0 ::1:6010 :::* LISTEN 1190/sshd: [email protected] tcp6 0 0 ::1:6011 :::* LISTEN 5116/sshd: [email protected] udp 0 0 0.0.0.0:10042 0.0.0.0:* 4399/dhclient udp 0 0 127.0.0.1:323 0.0.0.0:* 752/chronyd udp 0 0 0.0.0.0:68 0.0.0.0:* 4399/dhclient udp6 0 0 ::1:323 :::* 752/chronyd udp6 0 0 :::50626 :::* 4399/dhclient # netstat -antup 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:22 0.0.0.0:* LISTEN 1054/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1052/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1143/master tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 1190/sshd: [email protected] tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 5116/sshd: [email protected] tcp 0 52 172.18.250.108:22 172.18.4.1:49701 ESTABLISHED 1190/sshd: [email protected] tcp 0 0 172.18.250.108:22 172.18.4.1:49924 ESTABLISHED 5116/sshd: [email protected] tcp6 0 0 :::22 :::* LISTEN 1054/sshd tcp6 0 0 ::1:631 :::* LISTEN 1052/cupsd tcp6 0 0 ::1:25 :::* LISTEN 1143/master tcp6 0 0 ::1:6010 :::* LISTEN 1190/sshd: [email protected] tcp6 0 0 ::1:6011 :::* LISTEN 5116/sshd: [email protected] udp 0 0 0.0.0.0:10042 0.0.0.0:* 4399/dhclient udp 0 0 127.0.0.1:323 0.0.0.0:* 752/chronyd udp 0 0 0.0.0.0:68 0.0.0.0:* 4399/dhclient udp6 0 0 ::1:323 :::* 752/chronyd udp6 0 0 :::50626 :::* 4399/dhclient
显示路由表:netstat -rn
-r:显示内核路由表
-n:数字格式显示
# netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 172.18.0.1 0.0.0.0 UG 0 0 0 eno16777736 10.0.0.0 192.168.100.5 255.0.0.0 UG 0 0 &nbs以上是关于三大家族轻松管理CentOS 7网络属性配置的主要内容,如果未能解决你的问题,请参考以下文章