RHEL7 添加网卡并设置多个IP地址

首先在虚拟机管理界面中给该虚拟机添加一块虚拟网卡,VirtualBox虚拟机中要shutdown才能添加。

[root[email protected] ~]# nmcli device show | grep -i device   --查看网卡设备,我们可以看到新添加的enp0s8
GENERAL.DEVICE:                         virbr0
GENERAL.DEVICE:                         enp0s3
GENERAL.DEVICE:                         virbr0-nic
GENERAL.DEVICE:                         enp0s8
GENERAL.DEVICE:                         lo
[[email protected] ~]# 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的网卡配置文件:

[[email protected] ~]# nmcli connection add type ethernet con-name enp0s8 ifname enp0s8 autoconnect yes
Connection ‘enp0s8‘ (8bf108aa-9c89-4c2c-a5d3-3d9346b2c644) successfully added.
[[email protected] ~]# 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地址及其它信息:

[[email protected] ~]# 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网卡:

[[email protected] ~]# nmcli connection up enp0s8
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)
[[email protected] ~]# 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:

[[email protected] ~]# nmcli connection modify enp0s8 +ipv4.addresses 192.168.1.201/24 ipv4.gateway 192.168.1.99
[[email protected] ~]# nmcli connection down enp0s8   --重启网卡
Connection ‘enp0s8‘ successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)
[[email protected] ~]# nmcli connection up enp0s8
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)
[[email protected] ~]# 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
[[email protected] ~]# 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
[[email protected] ~]# 

给enp0s8再配置一个IPv6地址2001::1/64

[[email protected] ~]# nmcli connection modify enp0s8  ipv6.method manual ipv6.addresses 2001::1/64  ipv6.gateway 2001::1 ipv6.dns 2001::1
[[email protected] ~]# ping6 2001::1
connect: Network is unreachable
[[email protected] ~]# nmcli connection down enp0s8
Connection ‘enp0s8‘ successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)
[[email protected] ~]# nmcli connection up enp0s8
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/15)
[[email protected] ~]# 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
[[email protected] ~]# 
时间: 2024-10-05 08:49:25

RHEL7 添加网卡并设置多个IP地址的相关文章

linux下一块网卡设置多个ip地址

无论是在实际的生产坏境中,还是平时的练习中, 一个网卡设置多个ip地址是非常常见的,也是非常有用的. 我们以centos6.8系统为列, 在一块网卡上设置多个ip地址. 1>. 给一块网卡设置多个ip地址这个功能可能会受到NetworkManager服务的影响,首先关闭NetworkManager服务,并且开机自启也关闭. [[email protected] network-scripts]# service NetworkManager stop Stopping NetworkManage

ubuntu Server 设置主机静态 ip地址

ubuntu Server 设置主机静态 ip地址 1:先输入 ifconfig 查看当前网络配置 2:然后关闭 eth0 网卡 sudo ifdown eth0 3:配置静态ip sudo vim /etc/network/interfaces 打开文件,修改eth0的配置,设置您的ip,网关,子网掩码 4:此时,如果不配置dns ,ping不通的: sudo vim /etc/resolv.conf 添加nameserver 即可 5:保存退出 6:激活网卡eth0 sudo ifup et

CentOS 网络设置修改 指定IP地址 DNS 网关(转)

CentOS 网络设置修改 指定IP地址 DNS 网关(实测 笔记) 环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:Centos-6.5-x86_64 路由器网关:192.168.1.1 步骤: 1.查看网络MAC地址 [[email protected] ~]# cat /etc/udev/rules.d/70-persistent-net.rules 显示如下信息 # PCI device 0x15ad:0x07b0 (vmxnet3) SUBSY

电脑设置自动获取IP地址教程

当自己无线网络连接不上.或者电脑接了网线无法上网或者电脑只能登入qq无法打开网页等问题,那么就有可能是自己的电脑没有设置成自动获取IP地址,那么该怎么操作呢?下面我将根据自己的一些经验,与大家分享,如何设置自动获取IP地址! 1.打开[计算机]点击[打开控制面板] 2.选择网络和intemet 3.点击[网络和共享中心] 4.点击[更改适配器设置] 5.右键单击[本地连接]选择属性 备注:选择需要更改的网络适配器 6.选择[Internet协议版本4(TCP/IPv4)]选择属性 7.选择[自动

Azure经典门户创建VM,如何设置使用静态IP地址?

使用 Azure 经典管理门户中创建的虚拟机,无法使用静态IP 地址,在管理界面没有该设置.在新的管理门户中虽然有使用静态IP的设置,但是选项是灰色,无法修改,提示错误:This virtual machine can't be configured with a static private IP address because it's not deployed in a virtual network. 默认情况下,Azure中的虚拟机关机后重启,会重新分配IP地址.生产环境中,为了和其它

CentOS 6 网络设置修改 指定IP地址 DNS 网关(实测 笔记)_(转)

环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:Centos-6.5-x86_64 路由器网关:192.168.1.1 步骤: 1.查看网络MAC地址 [[email protected] ~]# cat /etc/udev/rules.d/70-persistent-net.rules 显示如下信息 # PCI device 0x15ad:0x07b0 (vmxnet3) SUBSYSTEM=="net", ACTION=="add

编辑网卡配置,手动配置IP地址

#vi /etc/sysconfig/network-scripts/ifcfg-eth0    //ifcfg-eth0表示系统当前网卡,此处不一定是eth0. DEVICE=eth0    //网卡名称. HWADDR=00:0C:29:90:59:8D    //网卡MAC. TYPE=Ethernet    //网卡类型,此处是以太网. UUID=5cb79d0d-a034-4657-b16f-de4d8b507e88    //网卡UUID号. ONBOOT=yes    //是否开机

CentOS 6 网络设置修改 指定IP地址 DNS 网关(转)

环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:Centos-6.5-x86_64 路由器网关:192.168.1.1 步骤: 1.查看网络MAC地址 [[email protected] ~]# cat /etc/udev/rules.d/70-persistent-net.rules 显示如下信息 # PCI device 0x15ad:0x07b0 (vmxnet3) SUBSYSTEM=="net", ACTION=="add

永久设置Ubuntu的IP地址

1. 查看当前Ubuntu的IP地址是多少?[email protected]:~$ ifconfiglo Link encap:Local Loopback -> 当前只有lo回环IP,没有以太网卡,需要主动激活网卡. inet addr:127.0.0.1 Mask:255.0.0.0 2. 激活以太网[email protected]:~$ sudo ifconfig eth0 up 3. 再次查看[email protected]:~$ ifconfigeth0 Link encap:E