nmcli,nmtui,iproute

注:nmcli和nmtui都是由NetworkManager服务提供的,使用前可以检查下此服务是否开启状态

nmcli

(1)查看网卡信息

[root@test2 ~]# nmcli conn show
NAME   UUID                                  TYPE      DEVICE
ens33  8a4633d3-f89d-30cc-b127-ea7d6c203705  ethernet  ens33
ens38  82eecf84-b7d4-3828-a310-6d2c24f8c976  ethernet  ens38

(2)添加,删除ip地址

#添加:如果设置的仅主机模式,不能添加ip
[root@test2 ~]# nmcli conn mod ens38 +ipv4.address 192.168.10.200/24
[root@test2 ~]# systemctl restart network
#删除:
[root@test2 ~]# nmcli conn mod ens38 -ipv4.address 192.168.10.200/24
[root@test2 ~]# systemctl restart network
#替换:如果设置的是动态ip的话,此条是添加
[root@test2 network-scripts]# nmcli conn mod ens38 ipv4.address 192.168.10.100/24
[root@test2 network-scripts]# systemctl restart network

(3)刷新网卡信息,不是重启服务

[root@test2 network-scripts]# nmcli conn down ens35;nmcli conn up ens38

(4)添加路由

[root@test2 network-scripts]# nmcli conn mod ens38 ipv4.gateway 192.168.10.1
[root@test2 network-scripts]# nmcli conn down ens38;nmcli conn up ens38
#注:route -n 可以查看路由列表

(5)添加dns

[root@test2 network-scripts]# nmcli conn mod ens38 ipv4.dns 223.6.6.6
[root@test2 network-scripts]# nmcli conn down ens38;nmcli conn up ens38

(6)删除链接配置

[root@test2 network-scripts]# nmcli conn mod ens38 ipv4.dns 223.6.6.6
#此时网卡名称可能会改变,用nmcli conn show查看

nmtui

图形化IP工具

iproute

  1. ARM记录管理
#(1)查看
[root@test1 test]# ip neigh
192.168.10.129 dev ens33 lladdr 00:0c:29:81:3f:41 STALE
192.168.10.12 dev ens33 lladdr 00:0c:29:81:3f:41 STALE
192.168.10.1 dev ens33 lladdr 00:50:56:c0:00:08 DELAY
192.168.10.2 dev ens33 lladdr 00:50:56:fd:1f:80 STALE

[root@test1 test]# ip neigh show 192.168.10.12
192.168.10.12 dev ens33 lladdr 00:0c:29:81:3f:41 STALE
[root@test1 test]# ip neigh ls 192.168.10.12
192.168.10.12 dev ens33 lladdr 00:0c:29:81:3f:41 STALE
[root@test1 test]# ip -s neigh ls 192.168.10.12
192.168.10.12 dev ens33 lladdr 00:0c:29:81:3f:41 used 1155/1155/1130 probes 4 STALE
[root@test1 test]# ip -s neigh show 192.168.10.12
192.168.10.12 dev ens33 lladdr 00:0c:29:81:3f:41 used 1161/1161/1136 probes 4 STALE

#(2)添加
[root@test1 test]# ip neigh add 192.168.10.111 lladdr 0:0:0:0:0:1 dev ens33
[root@test1 test]# ip neigh
192.168.10.129 dev ens33 lladdr 00:0c:29:81:3f:41 STALE
192.168.10.111 dev ens33 lladdr 00:00:00:00:00:01 PERMANENT
192.168.10.12 dev ens33 lladdr 00:0c:29:81:3f:41 STALE
192.168.10.1 dev ens33 lladdr 00:50:56:c0:00:08 REACHABLE
192.168.10.2 dev ens33 lladdr 00:50:56:fd:1f:80 STALE

#(3)删除
[root@test1 test]# ip neigh del 192.168.10.129 dev ens33
[root@test1 test]# ip neigh
192.168.10.111 dev ens33 lladdr 00:00:00:00:00:01 PERMANENT
192.168.10.12 dev ens33 lladdr 00:0c:29:81:3f:41 STALE
192.168.10.1 dev ens33 lladdr 00:50:56:c0:00:08 REACHABLE
192.168.10.2 dev ens33 lladdr 00:50:56:fd:1f:80 STALE
#(4)修改
[root@test1 test]# ip neigh change  192.168.10.111 dev ens33 lladdr 0:0:0:0:0:5
[root@test1 test]# ip neig
192.168.10.111 dev ens33 lladdr 00:00:00:00:00:05 PERMANENT
192.168.10.12 dev ens33 lladdr 00:0c:29:81:3f:41 STALE
192.168.10.1 dev ens33 lladdr 00:50:56:c0:00:08 REACHABLE
192.168.10.2 dev ens33 lladdr 00:50:56:fd:1f:80 STALE

[root@test1 test]# ip neigh change 192.168.10.111 lladdr 5:5:6:7:9:0 dev ens33 nud reachable
[root@test1 test]# ip neigh
192.168.10.111 dev ens33 lladdr 05:05:06:07:09:00 REACHABLE
192.168.10.12 dev ens33 lladdr 00:0c:29:81:3f:41 STALE
192.168.10.1 dev ens33 lladdr 00:50:56:c0:00:08 REACHABLE
192.168.10.2 dev ens33 lladdr 00:50:56:fd:1f:80 STALE
  1. 设备管理
#(1)查看
[root@test1 test]# ip link show ens33
[root@test1 test]# ip link ls ens33
2: ens33:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:6c:a9:65 brd ff:ff:ff:ff:ff:ff
[root@test1 test]# ip -s link ls ens33
[root@test1 test]# ip -s -s link show ens33
2: ens33:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:6c:a9:65 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    1694147    19959    0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    1143346    9075     0       0       0       0

[root@test1 test]# ip -s -s link show ens33
2: ens33:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:6c:a9:65 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    1702199    20061    0       0       0       0
    RX errors: length   crc     frame   fifo    missed
               0        0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    1148434    9123     0       0       0       0
    TX errors: aborted  fifo   window heartbeat transns
               0        0       0       0       2
#(2)增加
[root@test1 test]# ip link add ens36 name ens36 type veth  #虚拟网卡
[root@test1 test]# ip link show ens36
4: ens36@veth0:  mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 32:f3:0e:f4:10:57 brd ff:ff:ff:ff:ff:ff

[root@test1 test]# ip link add ens38 name br01 type bridge	#桥接网络
[root@test1 test]# ip a
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:6c:a9:65 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.11/24 brd 192.168.10.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
3: veth0@ens36:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 62:14:47:e6:2b:f9 brd ff:ff:ff:ff:ff:ff
4: ens36@veth0:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 32:f3:0e:f4:10:57 brd ff:ff:ff:ff:ff:ff
5: br01:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ae:ee:a3:7d:a1:66 brd ff:ff:ff:ff:ff:ff

#(3) 删除
[root@test1 test]# ip link del ens36
[root@test1 test]# ip link del br01
[root@test1 test]# ip a
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:6c:a9:65 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.11/24 brd 192.168.10.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
#(4)改
	#状态
	[root@test2 test]# ip link set ens38 down
	[root@test2 test]# ip link set ens38 up
	#修改传输队列,ifconfig查看
	[root@test2 test]# ip link set txqueuelen 500  ens38
	修改Mac地址
	[root@test2 test]# ip link set ens38 down
	[root@test2 test]# ip link set ens38 address 00:0c:29:81:3f:45
	#修改MTU
	[root@test2 test]# ip link set mtu 500 ens38
  1. 链接管理
#(1)查看
[root@test2 test]# ip addr ls ens38
[root@test2 test]# ip addr show ens38
[root@test2 test]# ip -s addr ls ens38
	RX:接收
	TX:发送
#(2)增加
[root@test2 test]# ip addr add 192.168.10.100/24 dev ens38  #(临时添加,不需要重启服务)
[root@test2 test]# nmcli conn mod ens38 +ipv4.address 192.168.10.100/24  #(修改配置文件,需要重启服务)
#(3)删除
[root@test2 test]# ip addr del 192.168.10.100 dev ens38
#(4)修改
[root@test2 test]# ip addr change 192.168.10.100/24 dev ens38 preferred_lft 60 valid_lft 60
  1. 路由管理
#(1)查
[root@test2 test]# ip route show 192.168.10.0/24
192.168.10.0/24 dev ens33 proto kernel scope link src 192.168.10.12 metric 102
192.168.10.0/24 dev ens38 proto kernel scope link src 192.168.10.129 metric 103
[root@test2 test]# ip route ls 192.168.10.0/24
[root@test2 test]# ip -s route ls 192.168.10.0/24
[root@test2 test]# ip -s -s route ls 192.168.10.0/24
#(2)增加
[root@test2 test]# ip route add 192.168.100.0 via 192.168.10.100 dev ens38
#(3)删除
[root@test2 test]# ip route del 192.168.100.0 via 192.168.10.100 dev ens38

------------------------------------------------------------------------------------------------------- 返回目录

你可能感兴趣的:(linux,网络管理)