如何为Linux虚拟机添加多块网卡

在VMWare虚拟机中添加网卡需要两个步骤:(1)添加网络适配器;(2)修改网卡配置文件。

一、添加网络适配器(网卡)

1、在VMWare虚拟机中单击【虚拟机】===>【设置】,在弹出的窗口中选择【网络适配器】,单击【添加】按钮,在【添加硬件向导】窗口中选择【网络适配器】。如下图所示:

在这里插入图片描述

2、单击【下一步】按钮,在弹出的窗口中根据需要选择所需的网络连接模式。然后重启系统。

在这里插入图片描述

二、修改网卡配置文件

添加网卡之后,使用ipconfig看不到新增网卡的信息。

[root@oracle network-scripts]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:B3:93:61  
          inet addr:192.168.1.202  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feb3:9361/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:578 errors:0 dropped:0 overruns:0 frame:0
          TX packets:202 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:49773 (48.6 KiB)  TX bytes:24682 (24.1 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

1、利用ifcfg-eth0网卡配置文件生成新增加网卡的配置文件
[root@oracle network-scripts]# cd /etc/sysconfig/network-scripts

[root@oracle network-scripts]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 ifcfg-eth1

[root@oracle network-scripts]# ls ifcfg*
ifcfg-eth0  ifcfg-eth1  ifcfg-lo
2、编辑ifcfg-eth1配置文件
[root@oracle network-scripts]# vim ifcfg-eth1

DEVICE=eth0
HWADDR=00:0C:29:B3:93:61
TYPE=Ethernet
UUID=cd246f31-87fd-4a26-a070-ccc6f8ed1c7a
ONBOOT=yes
BOOTPROTO=static
NM_CONTROLLED=yes

IPADDR=192.168.220.202
PREFIX=24
# GATEWAY=192.168.80.2
DNS1=192.168.80.2
DNS2=8.8.8.8
3、重启,查看网络信息
[root@oracle network-scripts]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:B3:93:61  
          inet addr:192.168.1.202  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feb3:9361/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2736 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2004 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:214479 (209.4 KiB)  TX bytes:232186 (226.7 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:B3:93:6B  
          inet addr:192.168.80.202  Bcast:192.168.80.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feb3:936b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:96 errors:0 dropped:0 overruns:0 frame:0
          TX packets:72 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8370 (8.1 KiB)  TX bytes:4992 (4.8 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:18 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1604 (1.5 KiB)  TX bytes:1604 (1.5 KiB)

三、配置网卡——使用一个网卡上外网另一个网卡接入局域网

1、配置外网网卡的网关
[root@oracle network-scripts]# vim /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=oracle.example.com
GATEWAY=192.168.1.1   ##配置为外网网卡的网关
2、配置DNS

可配置多个DNS,结果如下:

[root@oracle network-scripts]# vim /etc/resolv.conf

; generated by /sbin/dhclient-script
search localdomain oracle
nameserver 192.168.1.1
nameserver 192.168.80.2
nameserver 8.8.8.8
3、配置外网网卡的IP地址

外网网卡必须配置网关,结果如下:

[root@oracle network-scripts]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
HWADDR=00:0C:29:B3:93:61
TYPE=Ethernet
UUID=cd246f31-87fd-4a26-a070-ccc6f8ed1c7a
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static

IPADDR=192.168.1.202
PREFIX=24
GATEWAY=192.168.1.1   #网关
DNS1=192.168.1.1
DNS2=8.8.8.8
4、配置内网网卡的IP地址

外网网卡不能配置网关,结果如下:

[root@oracle network-scripts]# vim /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static

IPADDR=192.168.80.202
PREFIX=24
5、重新启动网络服务

重新启动网络服务,测试网络:

[root@wgx network-scripts]# service network restart
正在关闭接口 eth0:                                        [确定]
正在关闭接口 eth1:                                        [确定]
关闭环回接口:                                             [确定]
弹出环回接口:                                             [确定]
弹出界面 eth0: Determining if ip address 192.168.1.201 is already in use for device eth0...
                                                           [确定]
弹出界面 eth1: Determining if ip address 192.168.80.201 is already in use for device eth1...
                                                           [确定]
[root@wgx network-scripts]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121: icmp_seq=1 ttl=44 time=75.6 ms
64 bytes from 61.135.169.121: icmp_seq=2 ttl=44 time=409 ms
64 bytes from 61.135.169.121: icmp_seq=3 ttl=44 time=76.3 ms
64 bytes from 61.135.169.121: icmp_seq=4 ttl=44 time=97.1 ms
64 bytes from 61.135.169.121: icmp_seq=5 ttl=44 time=83.4 ms
64 bytes from 61.135.169.121: icmp_seq=6 ttl=44 time=77.9 ms
^C
--- www.a.shifen.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5378ms
rtt min/avg/max/mdev = 75.612/136.690/409.576/122.258 ms
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐