Linux7.0_nmcli_config_network

今天在自己的虚拟机导入了一份awr数据,同事需要看我就在虚拟机系统里添加了网卡的网卡,但是发现7以后配置网卡的方式稍微存在点变化,可以使用一下方法配置

  • nmtui– network manager 图形界面
  • nmcli– network manager command
  • ip — ip command

查看网卡

[root@oel7 network-scripts]# nmcli dev status
DEVICE  TYPE      STATE         CONNECTION
enp0s3  ethernet  connected     enp0s3
enp0s8  ethernet  connected     enp0s8
enp0s9  ethernet  disconnected  --
lo      loopback  unmanaged     --
显示了本机存在三个网卡

查看网络连接状态

[root@oel7 network-scripts]# nmcli con show
NAME    UUID                                  TYPE            DEVICE
enp0s8  00cb8299-feb9-55b6-a378-3fdc720e0bc6  802-3-ethernet  enp0s8
enp0s3  9f8a04b2-63ee-4150-b970-19536f4caae3  802-3-ethernet  enp0s3
 
enp0s9 网卡上没有网络接口存在

添加网络接口

nmcli con add type ethernet con-name eth-travel ifname enp0s9 --自动获取
 
 
[root@oel7 network-scripts]# nmcli con show
NAME        UUID                                  TYPE            DEVICE
eth-travel  105a6fc0-7d8d-4e71-b824-aea0fc2838ba  802-3-ethernet  enp0s9
enp0s8      00cb8299-feb9-55b6-a378-3fdc720e0bc6  802-3-ethernet  enp0s8
enp0s3      9f8a04b2-63ee-4150-b970-19536f4caae3  802-3-ethernet  enp0s3
 
[root@oel7 network-scripts]# ls -l ifcfg-*
-rw-r--r--. 1 root root 353 Oct 24 12:13 ifcfg-enp0s3
-rw-r--r--  1 root root 289 Jan 16 15:23 ifcfg-enp0s8
-rw-r--r--  1 root root 282 Jan 16 15:51 ifcfg-eth-travel
 
[root@oel7 network-scripts]# cat ifcfg-eth-travel
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth-travel
UUID=105a6fc0-7d8d-4e71-b824-aea0fc2838ba
DEVICE=enp0s9
ONBOOT=yes
 
查看网络连接参数
[root@oel7 network-scripts]# nmcli -p con show  eth-travel
===============================================================================
                    Connection profile details (eth-travel)
===============================================================================
connection.id:                          eth-travel
connection.uuid:                        105a6fc0-7d8d-4e71-b824-aea0fc2838ba
connection.interface-name:              enp0s9
connection.type:                        802-3-ethernet
connection.autoconnect:                 yes
connection.timestamp:                   1421394670
connection.read-only:                   no
connection.permissions:
connection.zone:                        --
connection.master:                      --
connection.slave-type:                  --
connection.secondaries:
connection.gateway-ping-timeout:        0
-------------------------------------------------------------------------------
802-3-ethernet.port:                    --
802-3-ethernet.speed:                   0
802-3-ethernet.duplex:                  --
802-3-ethernet.auto-negotiate:          yes
802-3-ethernet.mac-address:             --
802-3-ethernet.cloned-mac-address:      --
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu:                     auto
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype:            --
802-3-ethernet.s390-options:
-------------------------------------------------------------------------------
ipv4.method:                            auto
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:
ipv4.routes:
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes
-------------------------------------------------------------------------------
ipv6.method:                            auto
ipv6.dns:
ipv6.dns-search:
ipv6.addresses:
ipv6.routes:
ipv6.ignore-auto-routes:                no
ipv6.ignore-auto-dns:                   no
ipv6.never-default:                     no
ipv6.may-fail:                          yes
ipv6.ip6-privacy:                       -1 (unknown)
ipv6.dhcp-hostname:                     --
-------------------------------------------------------------------------------
===============================================================================
      Activate connection details (105a6fc0-7d8d-4e71-b824-aea0fc2838ba)
===============================================================================
GENERAL.NAME:                           eth-travel
GENERAL.UUID:                           105a6fc0-7d8d-4e71-b824-aea0fc2838ba
GENERAL.DEVICES:                        enp0s9
GENERAL.STATE:                          activated
GENERAL.DEFAULT:                        no
GENERAL.DEFAULT6:                       no
GENERAL.VPN:                            no
GENERAL.ZONE:                           --
GENERAL.DBUS-PATH:                      /org/freedesktop/NetworkManager/ActiveConnection/8
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/Settings/2
GENERAL.SPEC-OBJECT:                    --
GENERAL.MASTER-PATH:                    --
-------------------------------------------------------------------------------
IP4.ADDRESS[1]:                         ip = 192.168.1.108/24, gw = 192.168.1.1
IP4.DNS[1]:                             222.172.200.68
IP4.DNS[2]:                             61.166.150.123
-------------------------------------------------------------------------------
DHCP4.OPTION[1]:                        requested_domain_search = 1
DHCP4.OPTION[2]:                        requested_nis_domain = 1
DHCP4.OPTION[3]:                        requested_time_offset = 1
DHCP4.OPTION[4]:                        requested_broadcast_address = 1
DHCP4.OPTION[5]:                        requested_rfc3442_classless_static_routes = 1
DHCP4.OPTION[6]:                        requested_classless_static_routes = 1
DHCP4.OPTION[7]:                        requested_domain_name = 1
DHCP4.OPTION[8]:                        expiry = 1421401870
DHCP4.OPTION[9]:                        requested_wpad = 1
DHCP4.OPTION[10]:                       next_server = 0.0.0.0
DHCP4.OPTION[11]:                       broadcast_address = 192.168.1.255
DHCP4.OPTION[12]:                       dhcp_message_type = 5
DHCP4.OPTION[13]:                       requested_subnet_mask = 1
DHCP4.OPTION[14]:                       dhcp_lease_time = 7200
DHCP4.OPTION[15]:                       routers = 192.168.1.1
DHCP4.OPTION[16]:                       ip_address = 192.168.1.108
DHCP4.OPTION[17]:                       requested_static_routes = 1
DHCP4.OPTION[18]:                       requested_interface_mtu = 1
DHCP4.OPTION[19]:                       requested_nis_servers = 1
DHCP4.OPTION[20]:                       requested_ntp_servers = 1
DHCP4.OPTION[21]:                       subnet_mask = 255.255.255.0
DHCP4.OPTION[22]:                       domain_name_servers = 222.172.200.68 61.166.150.123
DHCP4.OPTION[23]:                       requested_ms_classless_static_routes = 1
DHCP4.OPTION[24]:                       requested_routers = 1
DHCP4.OPTION[25]:                       requested_domain_name_servers = 1
DHCP4.OPTION[26]:                       network_number = 192.168.1.0
DHCP4.OPTION[27]:                       requested_host_name = 1
DHCP4.OPTION[28]:                       dhcp_server_identifier = 192.168.1.1
-------------------------------------------------------------------------------
IP6.ADDRESS[1]:                         ip = fe80::a00:27ff:feb4:92f9/64, gw = ::
-------------------------------------------------------------------------------

删除连接

nmcli conn delete id eth-travel
 
[root@oel7 network-scripts]# nmcli conn show
NAME    UUID                                  TYPE            DEVICE
enp0s8  00cb8299-feb9-55b6-a378-3fdc720e0bc6  802-3-ethernet  enp0s8
enp0s3  9f8a04b2-63ee-4150-b970-19536f4caae3  802-3-ethernet  enp0s3
[root@oel7 network-scripts]#

添加静态ip

nmcli con add type ethernet con-name  eth-travel ifname enp0s9 ip4 192.168.1.30/24 gw4 192.168.1.1
 
[root@oel7 network-scripts]# nmcli conn show
NAME        UUID                                  TYPE            DEVICE
enp0s8      00cb8299-feb9-55b6-a378-3fdc720e0bc6  802-3-ethernet  enp0s8
enp0s3      9f8a04b2-63ee-4150-b970-19536f4caae3  802-3-ethernet  enp0s3
eth-travel  423e240a-8067-4926-81e1-5d137b3f146a  802-3-ethernet  enp0s9
[root@oel7 network-scripts]# cat ifcfg-
ifcfg-enp0s3      ifcfg-enp0s8      ifcfg-eth-travel  ifcfg-lo
[root@oel7 network-scripts]# cat ifcfg-e
ifcfg-enp0s3      ifcfg-enp0s8      ifcfg-eth-travel
[root@oel7 network-scripts]# cat ifcfg-eth-travel
TYPE=Ethernet
BOOTPROTO=none
IPADDR0=192.168.1.30
PREFIX0=24
GATEWAY0=192.168.1.1
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth-travel
UUID=423e240a-8067-4926-81e1-5d137b3f146a
DEVICE=enp0s9
ONBOOT=yes

添加dns

nmcli con mod eth-travel +ipv4.dns "8.8.8.8 8.8.4.4"
 
[root@oel7 network-scripts]# nmcli -p conn show eth-travel | grep dns
ipv4.dns:                               8.8.8.8, 8.8.4.4
ipv4.dns-search:
ipv4.ignore-auto-dns:                   no
ipv6.dns:
ipv6.dns-search:
ipv6.ignore-auto-dns:                   no
修改连接的ip
[root@oel7 network-scripts]# nmcli con edit type ethernet con-name eth-travel
 
===| nmcli interactive connection editor |===
 
Adding a new '802-3-ethernet' connection
 
Type 'help' or '?' for available commands.
Type 'describe [<setting>.<prop>]' for detailed property description.
 
You may edit the following settings: connection, 802-3-ethernet (ethernet), 802-1x, ipv4, ipv6, dcb
nmcli> set ipv4.addresses 192.168.122.88/24
Do you also want to set 'ipv4.method' to 'manual'? [yes]: y
nmcli> save
Saving the connection with 'autoconnect=yes'. That might result in an immediate activation of the connection.
Do you still want to save? [yes] y
Connection 'eth-travel' (b7fd478b-2b62-44cc-86a3-d0a2fb1cd3e9) successfully saved.
nmcli> help
------------------------------------------------------------------------------
---[ Main menu ]---
goto     [<setting> | <prop>]        :: go to a setting or property
remove   <setting>[.<prop>] | <prop> :: remove setting or reset property value
set      [<setting>.<prop> <value>]  :: set property value
describe [<setting>.<prop>]          :: describe property
print    [all]                       :: print the connection
verify   [all]                       :: verify the connection
save     [persistent|temporary]      :: save the connection
activate [<ifname>] [/<ap>|<nsp>]    :: activate the connection
back                                 :: go one level up (back)
help/?   [<command>]                 :: print this help
nmcli    <conf-option> <value>       :: nmcli configuration
quit                                 :: exit nmcli
------------------------------------------------------------------------------
nmcli> print all  --查看所有参数
===============================================================================
                    Connection profile details (eth-travel)
===============================================================================
connection.id:                          eth-travel
connection.uuid:                        b7fd478b-2b62-44cc-86a3-d0a2fb1cd3e9
connection.interface-name:              --
connection.type:                        802-3-ethernet
connection.autoconnect:                 yes
connection.timestamp:                   0
connection.read-only:                   no
connection.permissions:
connection.zone:                        --
connection.master:                      --
connection.slave-type:                  --
connection.secondaries:
connection.gateway-ping-timeout:        0
-------------------------------------------------------------------------------
802-3-ethernet.port:                    --
802-3-ethernet.speed:                   0
802-3-ethernet.duplex:                  --
802-3-ethernet.auto-negotiate:          yes
802-3-ethernet.mac-address:             --
802-3-ethernet.cloned-mac-address:      --
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu:                     auto
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype:            --
802-3-ethernet.s390-options:
-------------------------------------------------------------------------------
ipv4.method:                            manual
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:                         { ip = 192.168.122.88/24, gw = 0.0.0.0 }
ipv4.routes:
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes
-------------------------------------------------------------------------------
ipv6.method:                            auto
ipv6.dns:
ipv6.dns-search:
ipv6.addresses:
ipv6.routes:
ipv6.ignore-auto-routes:                no
ipv6.ignore-auto-dns:                   no
ipv6.never-default:                     no
ipv6.may-fail:                          yes
ipv6.ip6-privacy:                       -1 (unknown)
ipv6.dhcp-hostname:                     --
-------------------------------------------------------------------------------
nmcli>
 
nmcli> print ipv4  --查看ipv4相关参数
['ipv4' setting values]
ipv4.method:                            manual
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:                         { ip = 192.168.122.88/24, gw = 0.0.0.0 }
ipv4.routes:
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes
-------------------------------------------------------------------------------
此条目发表在 Linux 分类目录。将固定链接加入收藏夹。

评论功能已关闭。