文章目录
- 1. Vmvare设置 “编辑->虚拟机网络编辑”
- 2. 新建一个虚拟机并给它设置网卡
- 3. 配置eth0网卡为静态IP `vim /etc/sysconfig/network-scripts/ifcfg-eth0`
- 4、测试
1. Vmvare设置 “编辑->虚拟机网络编辑”
这里设置了3个虚拟网络(两个主机模式,这两个网络其实都没用到,然后配置了一个NAT模式,默认是动态IP,可以通过DHCP配置
修改动态变更范围、时间等,后续就把它改为静态IP)
如图可以看出这就是动态IP
![在这里插入图片描述](https://img-blog.csdnimg.cn/e6d8030e122542ddb67a022e24862fab.png
添加这3个虚拟网络后WINDOWS会多出这3个网络适配器
这里需要记住网关IP,linux配置网卡要用
2. 新建一个虚拟机并给它设置网卡
这里设置了两个网卡,一个NAT模式一个主机模式,故进入linux会看到这两个网卡eth0,eth1
这里安装了docker会有各docker0虚拟网卡,eth0,eth1就是配置的NAT模式 ,主机模式网卡,lo是默认都有的回环IP的虚拟网卡
[root@node1 ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:63:2c:f6:15 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.72.128 netmask 255.255.255.0 broadcast 192.168.72.255
inet6 fe80::c1de:2992:816a:3e07 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:2e:e1:98 txqueuelen 1000 (Ethernet)
RX packets 9816 bytes 988200 (965.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14247 bytes 2828027 (2.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 18 base 0x2000
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::20c:29ff:fe2e:e1a2 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:2e:e1:a2 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 70 bytes 12004 (11.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 19 base 0x2080
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
3. 配置eth0网卡为静态IP vim /etc/sysconfig/network-scripts/ifcfg-eth0
# 默认是如下动态IP (dhcp)配置
BOOTPROTO=dhcp
ONBOOT=yes
DEVICE=eth0
现在把eth0改为静态IP,注意设置的静态IP地址 ,可取192.168.72.0~192.168.72.255 前缀同网关,192.168.72.0一般是子网IP,192.168.72.2是网关,192.168.72.255是广播IP,故静态IP的末位不能是0,2,255
DEVICE=eth0
OXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static" # 使用静态IP地址,默认为dhcp
IPADDR="192.168.72.128" # 设置的静态IP地址 ,可取192.168.72.0~192.168.72.255 前缀同网关,192.168.72.0一般是子网IP,192.168.72.2是网关,192.168.72.255是广播IP,故静态IP的末位不能是0,2,255
NETMASK="255.255.255.0" # 子网掩码
GATEWAY="192.168.72.2" # 网关地址 就是上面说的那个地址
DNS1="114.114.114.114" # DNS服务器,不用改
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
UUID="95b614cd-79b0-4755-b08d-99f1cca7271b" #随便
ONBOOT="yes"
4、测试
使用nmcli
网卡管理工具查看各网卡状态,
[root@node-1 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
eth0 ethernet 已连接 System eth0
eth1 ethernet 已断开 --
docker0 bridge 未托管 --
lo loopback 未托管 --
可以ifconfig看到eth1的TX ,RX数据确实是有问题的,仅有一点输出流量,且 ifconfig eth0 down 之后ping jd.com是不通的了
[root@node-1 ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:31:14:fd:36 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.72.128 netmask 255.255.255.0 broadcast 192.168.72.255
inet6 fe80::c1de:2992:816a:3e07 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:2e:e1:98 txqueuelen 1000 (Ethernet)
RX packets 6986 bytes 695920 (679.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9519 bytes 1888928 (1.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 18 base 0x2000
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:2e:e1:a2 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 102 bytes 18244 (17.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 19 base 0x2080
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 32 bytes 2592 (2.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 32 bytes 2592 (2.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0