RHEL7 添加网卡并设置多个IP地址
Posted 遠離塵世の方舟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RHEL7 添加网卡并设置多个IP地址相关的知识,希望对你有一定的参考价值。
首先在虚拟机管理界面中给该虚拟机添加一块虚拟网卡,VirtualBox虚拟机中要shutdown才能添加。
[root@rhel7 ~]# nmcli device show | grep -i device --查看网卡设备,我们可以看到新添加的enp0s8 GENERAL.DEVICE: virbr0 GENERAL.DEVICE: enp0s3 GENERAL.DEVICE: virbr0-nic GENERAL.DEVICE: enp0s8 GENERAL.DEVICE: lo [root@rhel7 ~]# nmcli connection show ---还得添加网卡配置文件才能查看到enp0s8 NAME UUID TYPE DEVICE virbr0-nic c6a02e0f-24af-4b3b-983d-1643fee355df generic virbr0-nic virbr0 eecfd3a6-4d29-4f9c-a62c-1a30df56e011 bridge virbr0 enp0s3 df34c879-c2bd-4c82-ae7a-39e39a2228dd 802-3-ethernet enp0s3
添加enp0s8的网卡配置文件:
[root@rhel7 ~]# nmcli connection add type ethernet con-name enp0s8 ifname enp0s8 autoconnect yes Connection \'enp0s8\' (8bf108aa-9c89-4c2c-a5d3-3d9346b2c644) successfully added. [root@rhel7 ~]# nmcli connection show NAME UUID TYPE DEVICE virbr0-nic c6a02e0f-24af-4b3b-983d-1643fee355df generic virbr0-nic virbr0 eecfd3a6-4d29-4f9c-a62c-1a30df56e011 bridge virbr0 enp0s3 df34c879-c2bd-4c82-ae7a-39e39a2228dd 802-3-ethernet enp0s3 enp0s8 8bf108aa-9c89-4c2c-a5d3-3d9346b2c644 802-3-ethernet enp0s8
配置IP地址及其它信息:
[root@rhel7 ~]# nmcli connection modify enp0s8 ipv4.addresses 192.168.1.200/24 ipv4.gateway 192.168.1.99 ipv4.dns 192.168.1.1 ipv4.method manual connection.autoconnect yes
启动enp0s8网卡:
[root@rhel7 ~]# nmcli connection up enp0s8 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13) [root@rhel7 ~]# ip a s enp0s8 3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:79:3c:2c brd ff:ff:ff:ff:ff:ff inet 192.168.1.200/24 brd 192.168.1.255 scope global enp0s8 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe79:3c2c/64 scope link valid_lft forever preferred_lft forever
网卡添加配置完成。
============================
给enp0s8再配置一个IP地址192.168.1.201:
[root@rhel7 ~]# nmcli connection modify enp0s8 +ipv4.addresses 192.168.1.201/24 ipv4.gateway 192.168.1.99 [root@rhel7 ~]# nmcli connection down enp0s8 --重启网卡 Connection \'enp0s8\' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13) [root@rhel7 ~]# nmcli connection up enp0s8 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14) [root@rhel7 ~]# nmcli connection show NAME UUID TYPE DEVICE virbr0-nic c6a02e0f-24af-4b3b-983d-1643fee355df generic virbr0-nic virbr0 eecfd3a6-4d29-4f9c-a62c-1a30df56e011 bridge virbr0 enp0s3 df34c879-c2bd-4c82-ae7a-39e39a2228dd 802-3-ethernet enp0s3 enp0s8 8bf108aa-9c89-4c2c-a5d3-3d9346b2c644 802-3-ethernet enp0s8 [root@rhel7 ~]# ip addr show enp0s8 --查看添加成功 3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:79:3c:2c brd ff:ff:ff:ff:ff:ff inet 192.168.1.200/24 brd 192.168.1.255 scope global enp0s8 valid_lft forever preferred_lft forever inet 192.168.1.201/24 brd 192.168.1.255 scope global secondary enp0s8 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe79:3c2c/64 scope link valid_lft forever preferred_lft forever [root@rhel7 ~]#
给enp0s8再配置一个IPv6地址2001::1/64
[root@rhel7 ~]# nmcli connection modify enp0s8 ipv6.method manual ipv6.addresses 2001::1/64 ipv6.gateway 2001::1 ipv6.dns 2001::1 [root@rhel7 ~]# ping6 2001::1 connect: Network is unreachable [root@rhel7 ~]# nmcli connection down enp0s8 Connection \'enp0s8\' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14) [root@rhel7 ~]# nmcli connection up enp0s8 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/15) [root@rhel7 ~]# ping6 2001::1 PING 2001::1(2001::1) 56 data bytes 64 bytes from 2001::1: icmp_seq=1 ttl=64 time=0.062 ms 64 bytes from 2001::1: icmp_seq=2 ttl=64 time=0.116 ms 64 bytes from 2001::1: icmp_seq=3 ttl=64 time=0.119 ms ^C --- 2001::1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2000ms rtt min/avg/max/mdev = 0.062/0.099/0.119/0.026 ms [root@rhel7 ~]#
以上是关于RHEL7 添加网卡并设置多个IP地址的主要内容,如果未能解决你的问题,请参考以下文章