修改網卡設定

  1. 不必刪除設定,直接使用 modify 選項變更設定。設定 ipv4 位址 192.168.122.8、遮罩 255.255.255.0、GATEWAY 192.168.122.1 及 DNS 192.168.122.1,最後一定要設定 ipv4.method 為 manual,將網路連線設定為手動,也就是自行設定 IP,不是由 DHCP 自動取得,否則原 DHCP 取得的 IP 還會存在。
    [root@999999 ~]# nmcli connection modify enp1s0 \
    ipv4.addresses 192.168.122.8/24 \
    ipv4.gateway 192.168.122.1 \
    ipv4.dns 192.168.122.1 \
    ipv4.method manual
    
  2. 將網路連線 enp1s0 啟動。
    [root@999999 ~]# nmcli connection up enp1s0 
    Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
    
  3. 查看網卡設定,看手動設定是否正確?
    [root@999999 ~]# nmcli connection show enp1s0 | grep -iE ipv?4
    ipv4.method:                            manual
    ipv4.dns:                               192.168.122.1
    ipv4.dns-search:                        --
    ipv4.dns-options:                       --
    ipv4.dns-priority:                      0
    ipv4.addresses:                         192.168.122.8/24
    ipv4.gateway:                           192.168.122.1
    ipv4.routes:                            --
    ipv4.route-metric:                      -1
    ipv4.route-table:                       0 (unspec)
    ipv4.routing-rules:                     --
    ipv4.ignore-auto-routes:                no
    ipv4.ignore-auto-dns:                   no
    ipv4.dhcp-client-id:                    --
    ipv4.dhcp-iaid:                         --
    ipv4.dhcp-timeout:                      0 (default)
    ipv4.dhcp-send-hostname:                yes
    ipv4.dhcp-hostname:                     --
    ipv4.dhcp-fqdn:                         --
    ipv4.dhcp-hostname-flags:               0x0 (none)
    ipv4.never-default:                     no
    ipv4.may-fail:                          yes
    ipv4.required-timeout:                  -1 (default)
    ipv4.dad-timeout:                       -1 (default)
    ipv4.dhcp-vendor-class-identifier:      --
    ipv4.dhcp-reject-servers:               --
    IP4.ADDRESS[1]:                         192.168.122.8/24
    IP4.GATEWAY:                            192.168.122.1
    IP4.ROUTE[1]:                           dst = 192.168.122.0/24, nh = 0.0.0.0, mt = 100
    IP4.ROUTE[2]:                           dst = 0.0.0.0/0, nh = 192.168.122.1, mt = 100
    IP4.DNS[1]:                             192.168.122.1