systemd对网络设备的命名方式:
上述命名机制中,有的需要biosdevname程序的参与,所以必须安装biosdevname程序且启用它。
基于固件、 设备结构、设备类型三种方式:
由两个字母开头标示固件
设备结构
//修改网卡配置文件
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-ens160
[root@localhost network-scripts]# mv ifcfg-ens160 ifcfg-eth0
[root@localhost network-scripts]# ls
ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0 //把ens160换成eth0
UUID=cf57c3f1-7eaf-489c-86d4-2ebbc39f6105
DEVICE=eth0 //把ens160换成eth0
ONBOOT=yes
[root@localhost ~]# vim /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap net.ifnames=0 biosdevname=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
为grub2生成配置文件
//为grub2生成配置文件
[root@localhost ~]# grub2-mkconfig -o /etc/grub2.cfg (-o:outpu更新配置文件更新到/etc/grub2.cfg)
Generating grub configuration file …
done
[root@localhost ~]# reboot
//生成配置文件后需要重启
查看网卡名称
//之前的网卡名称
1: lo:
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: ens160:
link/ether 00:0c:29💿6a:1b brd ff:ff:ff:ff:ff:ff
inet 192.168.174.128/24 brd 192.168.174.255 scope global dynamic noprefixroute ens160
valid_lft 1750sec preferred_lft 1750sec
inet6 fe80::dc83:4685:5028:2c09/64 scope link noprefixroute
valid_lft forever preferred_lft forever
//重设网卡名之后
[root@localhost ~]# ip a
1: lo:
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: eth0:
link/ether 00:0c:29💿6a:1b brd ff:ff:ff:ff:ff:ff
inet 192.168.174.128/24 brd 192.168.174.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::6cda:49cd:383e:cfa3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@localhost ~]# ifconfig
eth0: flags=4163
inet 192.168.174.128 netmask 255.255.255.0 broadcast 192.168.174.255
inet6 fe80::6cda:49cd:383e:cfa3 prefixlen 64 scopeid 0x20
ether 00:0c:29💿6a:1b txqueuelen 1000 (Ethernet)
RX packets 95 bytes 9605 (9.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 93 bytes 10685 (10.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 12 bytes 1020 (1020.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 1020 (1020.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# ifconfig eth0
eth0: flags=4163
inet 192.168.174.128 netmask 255.255.255.0 broadcast 192.168.174.255
inet6 fe80::6cda:49cd:383e:cfa3 prefixlen 64 scopeid 0x20
ether 00:0c:29💿6a:1b txqueuelen 1000 (Ethernet)
RX packets 111 bytes 10847 (10.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 108 bytes 12827 (12.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# ifconfig -a
eth0: flags=4163
inet 192.168.174.128 netmask 255.255.255.0 broadcast 192.168.174.255
inet6 fe80::6cda:49cd:383e:cfa3 prefixlen 64 scopeid 0x20
ether 00:0c:29💿6a:1b txqueuelen 1000 (Ethernet)
RX packets 134 bytes 12673 (12.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 124 bytes 14771 (14.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 12 bytes 1020 (1020.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 1020 (1020.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
UP: 网卡处于活动状态
BROADCAST: 支持广播
RUNNING: 网线已接入
MULTICAST: 支持组播
MTU: 最大传输单元(字节) ,即此接口一次所能传输的最大封包
inet: 显示IPv4地址行
inet6: 显示IPv6地址行
link/enther: 指设备硬件(MAC )地址
txqueuelen: 传输缓存区长度大小
RX packets: 接收的数据包
TX packets: 发送的数据包
errors: 总的收包的错误数量
dropped: 由于各种原因,导致拷贝在内存过程中被丢弃
collisions: 网络信号冲突情况,值不为0则可能存在网络故障
ip [ option ] object { command | help }
object :
link:网络接口
addr:协议地址
route:路由
[root@localhost ~]# ip link show
1: lo:
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0:
link/ether 00:0c:29💿6a:1b brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# ip -s link show
1: lo:
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
RX: bytes packets errors dropped overrun mcast
1020 12 0 0 0 0
TX: bytes packets errors dropped carrier collsns
1020 12 0 0 0 0
2: eth0:
link/ether 00:0c:29💿6a:1b brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
21460 245 0 0 0 0
TX: bytes packets errors dropped carrier collsns
21963 202 0 0 0 0
语法:ip link set devname { up | down}
[root@localhost ~]# ip link set lo down
[root@localhost ~]# ip link set lo up
语法:ip addr add ip/prefix dev devname
[root@localhost ~]# ip addr show eth0
2: eth0:
link/ether 00:0c:29💿6a:1b brd ff:ff:ff:ff:ff:ff
inet 192.168.174.128/24 brd 192.168.174.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::6cda:49cd:383e:cfa3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@localhost ~]# ip addr add 192.168.174.150/24 dev eth0
[root@localhost ~]# ip addr show eth0
2: eth0:
link/ether 00:0c:29💿6a:1b brd ff:ff:ff:ff:ff:ff
inet 192.168.174.128/24 brd 192.168.174.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet 192.168.174.150/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::6cda:49cd:383e:cfa3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
语法:ip addr del ip/prefix dev devname
[root@localhost ~]# ip addr show eth0
2: eth0:
link/ether 00:0c:29💿6a:1b brd ff:ff:ff:ff:ff:ff
inet 192.168.174.128/24 brd 192.168.174.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet 192.168.174.150/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::6cda:49cd:383e:cfa3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@localhost ~]# ip addr del 192.168.174.150/24 dev eth0
[root@localhost ~]# ip addr show eth0
2: eth0:
link/ether 00:0c:29💿6a:1b brd ff:ff:ff:ff:ff:ff
inet 192.168.174.128/24 brd 192.168.174.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::6cda:49cd:383e:cfa3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
语法:ip addr show devname
[root@localhost ~]# ip addr show
[root@localhost ~]# ip addr show eth0
2: eth0:
link/ether 00:0c:29💿6a:1b brd ff:ff:ff:ff:ff:ff
inet 192.168.174.128/24 brd 192.168.174.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::6cda:49cd:383e:cfa3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
Linux主机之间是使用IP进行通信,假设A主机和B主机同在一个网段内且网卡都处于激活状态,则A具备和B直接通信的能力,但如果A主机和B主机处于两个不同的网段,则A必须通过路由器才能和B通信,路由器属于IT设备的基础设施,每个网段 都应该至少有一个网关
[root@localhost ~]# 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.174.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.174.2 0.0.0.0 UG 100 0 0 eth0
192.168.174.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
语法:route add [ net | host ] ip/prefix gw dev devname (net:主机路由;host:主机路由)
[root@localhost ~]# route add -net 192.168.1.0/24 gw 192.168.174.2 dev eth0
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.174.2 0.0.0.0 UG 100 0 0 eth0
192.168.1.0 192.168.174.2 255.255.255.0 UG 0 0 0 eth0
192.168.174.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@localhost ~]# route add -net 0.0.0.0/0 gw 192.168.174.2 dev eth0
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.174.2 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.174.2 0.0.0.0 UG 100 0 0 eth0 (这条路由条目是原本就有的)
192.168.1.0 192.168.174.2 255.255.255.0 UG 0 0 0 eth0
192.168.174.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@localhost ~]# route add -host 192.168.174.150 gw 192.168.174.2
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.174.2 0.0.0.0 UG 100 0 0 eth0
192.168.174.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
192.168.174.150 192.168.174.2 255.255.255.255 UGH 0 0 0 eth0
[root@localhost ~]# route del -host 192.168.174.150
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.174.2 0.0.0.0 UG 100 0 0 eth0
192.168.174.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
网络配置文件:/etc/sysconfig/network
NETWORKING= [ yes | no ]:设置整个系统是否启用网络功能,若设为no,则无论网卡如何设置都不难使用网络功能
HOSTNAME:设置主机名
网卡接口的配置文件路径:/etc/sysconfig/network-scripts/ifcfg-devname
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
UUID=cf57c3f1-7eaf-489c-86d4-2ebbc39f6105
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none //引导协议,可选值有{static /none / dhcp /bootp}
NM_ CONTROLLED //NM是NetworkManager的简写,可选值有{yes/no}
TYPE //接口类型;常见的接口类型有: Etherdet, Bridge
UUID //设备的惟一标识
HWADDR //硬件地址,要与硬件中的地址保持一-致,可省
IPADDR=172.16.12.130 //固定IP地址
PREFIX=24 //子网掩码
NETMASK=255.255.255.0 //子网掩码
GATEWAY=172.16.12.2 //默认网关
DNS1=172.16.12.2 //第一个DNS服务器指向
DNS2 //第二个DNS服务器指向
DNS3 //第三个DNS服务器指向
DEVICE=eth1 //关联的设备名称,要与文件名的后半部INTERFACE_ NAME"保持一致
NAME="eth1" //连接名称
ONB00T=yes //在系统引导时是否自动激活此网络接口,可选值有{ yes / no }
DEFROUTE=yes //将接口设定为默认路由{ yes |no }
USERCTL={yes |no} //是否允许普通用户控制此接口的启用与禁用
PEERDNS={yes |no} //是否在BOOTPROTO为dhcp时接受由dhcp服务器指定的DNS地址
/etc/sysconfig/network-scripts/route-eth0(route-网卡设备名称)
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vim route-eth0
192.168.11.0/24 via 192.168.174.2
192.168.12.0/24 via 192.168.174.2
192.168.13.0/24 via 192.168.174.2
[root@localhost network-scripts]# ifdown eth0;ifup eth0
成功停用连接 "eth0"(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/19)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/21)
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.11.0 192.168.174.2 255.255.255.0 UG 100 0 0 eth0
192.168.12.0 192.168.174.2 255.255.255.0 UG 100 0 0 eth0
192.168.13.0 192.168.174.2 255.255.255.0 UG 100 0 0 eth0
192.168.174.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vim route-eth0
ADDRESS0=192.168.1.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.174.2
ADDRESS1=192.168.2.0
NETMASK1=255.255.255.0
GATEWAY1=192.168.174.2
[root@localhost network-scripts]# ifdown eth0;ifup eth0
成功停用连接 "eth0"(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/17)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/19)
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 192.168.174.2 255.255.255.0 UG 100 0 0 eth0
192.168.2.0 192.168.174.2 255.255.255.0 UG 100 0 0 eth0
192.168.174.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vim route-eth0
192.168.1.1/32 via 192.168.174.2
192.168.2.2/32 via 192.168.174.2
192.168.3.3/32 via 192.168.174.2
[root@localhost network-scripts]# ifdown eth0;ifup eth0
成功停用连接 "eth0"(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/21)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/23)
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.1 192.168.174.2 255.255.255.255 UGH 100 0 0 eth0
192.168.2.2 192.168.174.2 255.255.255.255 UGH 100 0 0 eth0
192.168.3.3 192.168.174.2 255.255.255.255 UGH 100 0 0 eth0
192.168.174.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
/etc/resolv.conf
[root@localhost ~]# vim /etc/resolv.conf
nameserver 8.8.8.8
//查看网卡的dns
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
UUID=cf57c3f1-7eaf-489c-86d4-2ebbc39f6105
DEVICE=eth0
ONBOOT=yes
DNS1=8.8.8.8
IPADDR=192.168.174.128
PREFIX=24
//只需更改网卡里面的的DNS,不需要更改/etc/resolv.conf里面的内容
1️⃣:RHEL/CentOS7系统默认使用NetworkManager来提供网络服务,这是一种动态管理网络配置的守护进程,能够让网络设备保持连接状态。
2️⃣:NetworkManager提供的命令行和图形配置工具对网络进行设定,设定保存的配置文件。
3️⃣:在/etc/sysconf ig/network-scripts目录下,工具有nmcli, nmtui, nm- connect ion-editor
4️⃣:device物理设备,例如ens33 , enp2s0, virbr0, team0
5️⃣:connection连接设置,具体网络配置方案:
不同的网络连接配置可以应用到相同的物理设备,但物理设备同一时间只能应用其中某个网络连接
针对物理网络接口,设定不同的网络连接,在不同的使用环境中激活相应的网络连接,就可以实现网络配置信息的自动切换了
[root@localhost ~]# systemctl status NetworkManager
● NetworkManager.service - Network Manager
Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-08-18 05:32:03 CST; 38min ago
Docs: man:NetworkManager(8)
Main PID: 5188 (NetworkManager)
Tasks: 3 (limit: 12356)
Memory: 4.4M
CGroup: /system.slice/NetworkManager.service
└─5188 /usr/sbin/NetworkManager --no-daemon
8月 18 05:58:40 localhost.localdomain NetworkManager[5188]:
8月 18 05:58:40 localhost.localdomain NetworkManager[5188]:
8月 18 05:58:40 localhost.localdomain NetworkManager[5188]:
8月 18 05:58:40 localhost.localdomain NetworkManager[5188]:
8月 18 05:58:40 localhost.localdomain NetworkManager[5188]:
8月 18 05:58:40 localhost.localdomain NetworkManager[5188]:
8月 18 05:58:40 localhost.localdomain NetworkManager[5188]:
8月 18 05:58:40 localhost.localdomain NetworkManager[5188]:
8月 18 05:58:40 localhost.localdomain NetworkManager[5188]:
8月 18 05:58:40 localhost.localdomain NetworkManager[5188]:
[root@localhost ~]# nmcli device
DEVICE TYPE STATE CONNECTION
eth0 ethernet 已连接 eth0
lo loopback 未托管 --
[root@localhost ~]# nmcli device show
GENERAL.DEVICE: eth0
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:0C:29:CD:6A:1B
GENERAL.MTU: 1500
GENERAL.STATE: 100(已连接)
GENERAL.CONNECTION: eth0
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/25
WIRED-PROPERTIES.CARRIER: 开
IP4.ADDRESS[1]: 192.168.174.128/24
IP4.GATEWAY: --
IP4.ROUTE[1]: dst = 192.168.174.0/24, nh = 0.0.0.0, mt = 100
IP4.ROUTE[2]: dst = 192.168.1.1/32, nh = 192.168.174.2, mt = 100
IP4.ROUTE[3]: dst = 192.168.2.2/32, nh = 192.168.174.2, mt = 100
IP4.ROUTE[4]: dst = 192.168.3.3/32, nh = 192.168.174.2, mt = 100
IP4.DNS[1]: 8.8.8.8
IP6.ADDRESS[1]: fe80::6cda:49cd:383e:cfa3/64
IP6.GATEWAY: --
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 100
IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255
GENERAL.DEVICE: lo
GENERAL.TYPE: loopback
GENERAL.HWADDR: 00:00:00:00:00:00
GENERAL.MTU: 65536
GENERAL.STATE: 10(未托管)
GENERAL.CONNECTION: --
GENERAL.CON-PATH: --
IP4.ADDRESS[1]: 127.0.0.1/8
IP4.GATEWAY: --
IP6.ADDRESS[1]: ::1/128
IP6.GATEWAY: --
[root@localhost ~]# nmcli device show eth0
GENERAL.DEVICE: eth0
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:0C:29:CD:6A:1B
GENERAL.MTU: 1500
GENERAL.STATE: 100(已连接)
GENERAL.CONNECTION: eth0
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/25
WIRED-PROPERTIES.CARRIER: 开
IP4.ADDRESS[1]: 192.168.174.128/24
IP4.GATEWAY: --
IP4.ROUTE[1]: dst = 192.168.174.0/24, nh = 0.0.0.0, mt = 100
IP4.ROUTE[2]: dst = 192.168.1.1/32, nh = 192.168.174.2, mt = 100
IP4.ROUTE[3]: dst = 192.168.2.2/32, nh = 192.168.174.2, mt = 100
IP4.ROUTE[4]: dst = 192.168.3.3/32, nh = 192.168.174.2, mt = 100
IP4.DNS[1]: 8.8.8.8
IP6.ADDRESS[1]: fe80::6cda:49cd:383e:cfa3/64
IP6.GATEWAY: --
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 100
IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255
[root@localhost ~]# nmcli connection
NAME UUID TYPE DEVICE
eth0 cf57c3f1-7eaf-489c-86d4-2ebbc39f6105 ethernet eth0
有线连接 1 a026ad4d-b586-32c4-908a-0501f9f2b522 ethernet --
[root@localhost ~]# nmcli connection show eth0
connection.id: eth0
connection.uuid: cf57c3f1-7eaf-489c-86d4-2ebbc39f6105
connection.stable-id: --
connection.type: 802-3-ethernet
connection.interface-name: eth0
connection.autoconnect: 是
connection.autoconnect-priority: 0
connection.autoconnect-retries: -1 (default)
connection.multi-connect: 0(default)
connection.auth-retries: -1
connection.timestamp: 1597702924
connection.read-only: 否
connection.permissions: --
connection.zone: --
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1(default)
………..
ping命令常用选项:
-c :指定ping包的次数
-i :指定ping包发送间隔
-w :如果pingh'm没有回应。则在指定超时后退出
实例:
//指定ping包次数
[root@localhost ~]# ping -c 3 www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=128 time=25.10 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=128 time=25.4 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=128 time=23.3 ms
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 5ms
rtt min/avg/max/mdev = 23.331/24.910/25.977/1.154 ms
//指定ping包的时间间隔
[root@localhost ~]# ping -i 2 -c 3 www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=128 time=23.8 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=128 time=24.8 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=128 time=21.9 ms
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 10ms
rtt min/avg/max/mdev = 21.906/23.477/24.759/1.182 ms
[root@localhost ~]# host www.baidu.com
www.baidu.com is an alias for www.a.shifen.com.
www.a.shifen.com has address 14.215.177.38
www.a.shifen.com has address 14.215.177.39
[root@localhost ~]# nslookup www.baidu.com
Server: 192.168.174.2
Address: 192.168.174.2#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 14.215.177.39
Name: www.a.shifen.com
Address: 14.215.177.38
[root@localhost ~]# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default _gateway 0.0.0.0 UG 0 0 0 eth0
192.168.174.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@localhost ~]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.174.2 0.0.0.0 UG 0 0 0 eth0
192.168.174.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@localhost ~]# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 0 localhost.localdoma:ssh 192.168.174.1:9531 ESTABLISHED
tcp 0 0 localhost.localdoma:ssh 192.168.174.1:12204 ESTABLISHED
tcp 0 208 localhost.localdoma:ssh 192.168.174.1:4293 ESTABLISHED
tcp6 0 0 [::]:ssh [::]:* LISTEN
raw6 0 0 [::]:ipv6-icmp [::]:* 7
Active UNIX domain sockets (servers and established)
……….
[root@localhost ~]# netstat -p
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 localhost.localdoma:ssh 192.168.174.1:9531 ESTABLISHED 1220/sshd: root [pr
tcp 0 0 localhost.localdoma:ssh 192.168.174.1:12204 ESTABLISHED 1412/sshd: root [pr
tcp 0 36 localhost.localdoma:ssh 192.168.174.1:4293 ESTABLISHED 5011/sshd: root [pr
Active UNIX domain sockets (w/o servers)
…………
[root@localhost ~]# netstat -antlp
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 1010/sshd
tcp 0 0 192.168.174.128:22 192.168.174.1:9531 ESTABLISHED 1220/sshd: root [pr
tcp 0 0 192.168.174.128:22 192.168.174.1:12204 ESTABLISHED 1412/sshd: root [pr
tcp 0 36 192.168.174.128:22 192.168.174.1:4293 ESTABLISHED 5011/sshd: root [pr
tcp6 0 0 :::22 :::* LISTEN 1010/sshd
options:
-t: tcp协议相关-u: udp协议相关-W:裸套接字相关-x: unix套接字相关-l: listen状态的连接-a:所有
-n:数字格式
-p:相关的程序及pid-e:扩展的信息
-m:内存用量
-0:显示计时器信息
FILTERs:
FILTER := [ state TCP-STATE] [ EXPRESSION ]
如: ss -antlp state ESTABLISHED
[root@localhost ~]# ss -antlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1010,fd=4))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=1010,fd=6))
[root@localhost ~]# ss -antlp state ESTABLISHED
Recv-Q Send-Q Local Address:Port Peer Address:Port
0 0 192.168.174.128:22 192.168.174.1:9531 users:(("sshd",pid=1233,fd=5),("sshd",pid=1220,fd=5))
0 0 192.168.174.128:22 192.168.174.1:12204 users:(("sshd",pid=1414,fd=5),("sshd",pid=1412,fd=5))
0 36 192.168.174.128:22 192.168.174.1:4293 users:(("sshd",pid=5013,fd=5),("sshd",pid=5011,fd=5))
常见的state:
tcp finite state machine: 有限状态机
LISTENING:监听
ESTABLISHED:已建立的连接
EXPRESSION:
dport =
sport =
示例: '( dport = :ssh or sport = :ssh)',此处的ssh也即服务名可以使用其对应的端口号代替
[root@localhost ~]# ss -antlp state ESTABLISHED '( dport = :ssh or sport = :ssh )'
Recv-Q Send-Q Local Address:Port Peer Address:Port
0 0 192.168.174.128:22 192.168.174.1:9531 users:(("sshd",pid=1233,fd=5),("sshd",pid=1220,fd=5))
0 0 192.168.174.128:22 192.168.174.1:12204 users:(("sshd",pid=1414,fd=5),("sshd",pid=1412,fd=5))
0 36 192.168.174.128:22 192.168.174.1:4293 users:(("sshd",pid=5013,fd=5),("sshd",pid=5011,fd=5))
http 80/tcp
httpd 443/tcp
ssh 22/tcp
ftp 20,21/tcp
mysql 3306/tc[
rsync 873/rsync
redis 6379/tcp
Windows远程:3389/tcp
dhcp 67/tcp
dns 53/tcp
MSSQL 1433/tcp
tomcat 8080
postfix 25
手机扫一扫
移动阅读更方便
你可能感兴趣的文章