VMware虚拟机Centos7配置双网卡双IP踩坑

VMware虚拟机Centos7配置双网卡双IP踩坑

    • 基础环境配置
      • 环境:Centos7
      • 配置:网卡1配置NAT模式,网卡二配置仅主机模式
    • VMware新增网卡后,ifconfig网卡不显示问题
    • copy网卡配置ifcfg-**重命名后,重启报错
      • 原因:
      • 修改:

基础环境配置

环境:Centos7

配置:网卡1配置NAT模式,网卡二配置仅主机模式

VMware新增网卡后,ifconfig网卡不显示问题

  • 判断网络适配器2(新网卡)是否添加成功;前往目录/proc/sys/net/ipv4/conf下,查看是否存在新的网卡目录;即ens36
[root@centos7_phpstudy conf]# cd /proc/sys/net/ipv4/conf
[root@centos7_phpstudy conf]# ll
total 0
dr-xr-xr-x. 1 root root 0 Jan 20 22:24 all
dr-xr-xr-x. 1 root root 0 Jan 20 22:24 default
dr-xr-xr-x. 1 root root 0 Jan 20 22:25 docker0
dr-xr-xr-x. 1 root root 0 Jan 20 22:25 ens33
dr-xr-xr-x. 1 root root 0 Jan 20 22:25 ens36
dr-xr-xr-x. 1 root root 0 Jan 20 22:25 lo
[root@centos7_phpstudy conf]# pwd
/proc/sys/net/ipv4/conf

copy网卡配置ifcfg-**重命名后,重启报错

  • 在网卡配置目录/etc/sysconfig/network-scripts下,复制已存在的ifcfg-ens33配置;
  • 并重新启动;
[root@centos7_phpstudy network-scripts]# service network restart
Restarting network (via systemctl):  Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.              
												[FAILED]

原因:

  1. 我们到/proc/sys/net/ipv4/conf目录下查看网络设备,发现新增的网卡被Linux系统命名为ens36;
  2. 我们copy原先网卡配置ifcfg-ens33,将其重命名为了ifcfg-ens22
  3. 也就是说linux系统识别不到我们为设备ens36配置的ifcfg-ens22网卡配置;(也就是不能随便命名),ens36对应配置文件名称应为:ifcfg-ens36;
  4. 因此将ifcfg-ens22,重命名为ifcfg-ens36即可;

修改:

  • 查看并修改新增的网卡配置名称ifcfg-ens36;
[root@centos7_phpstudy network-scripts]#pwd
/etc/sysconfig/network-scripts
[root@centos7_phpstudy network-scripts]#
[root@centos7_phpstudy network-scripts]# ll ifcfg-*
-rw-r--r--. 1 root root 419 May 14  2021 ifcfg-ens33
-rw-r--r--. 1 root root 353 Jan 20 23:16 ifcfg-ens36
-rw-r--r--. 1 root root 254 May 22  2020 ifcfg-lo
  • 网卡ifcfg-ens36内的DEVICE字段也需要修改为ens36
[root@centos7_phpstudy network-scripts]# vim ifcfg-ens36
TYPE="Ethernet"
PROXY_METHOD="none"
##ONBOOT="yes"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="yes"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
DEVICE="ens36"
ONBOOT="yes"
IPADDR="192.168.22.129"
NETMASK="255.255.255.0"
DNS1=8.8.8.8
DNS2=114.114.114.114
~                                                                                                                                                                                         
~                                                                                                                       
  • 重启network;
[root@centos7_phpstudy network-scripts]# service network restart
Restarting network (via systemctl):                        [  OK  ]
  • 查看网卡和IP
[root@centos7_phpstudy network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.138.20  netmask 255.255.255.0  broadcast 192.168.138.255
        inet6 fe80::250:56ff:fe2f:a86c  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:2f:a8:6c  txqueuelen 1000  (Ethernet)
        RX packets 937  bytes 222124 (216.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 688  bytes 95959 (93.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.22.129  netmask 255.255.255.0  broadcast 192.168.22.255
        inet6 fe80::20c:29ff:fe12:b11d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:12:b1:1d  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 30  bytes 2152 (2.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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 1111  bytes 68013 (66.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1111  bytes 68013 (66.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@centos7_phpstudy network-scripts]# 

你可能感兴趣的:(LINUX,linux,网络,vmware)