VMware下linux填加新网卡后,ifconfig没有新网卡信息

VMware 下Centos 6.8一开始只有一块网卡host-only模式用于与windows客户机互联
现填加一块网卡启用NAT模式上网
在VMware里面填加另一块网卡后,虚拟机里面ifconfig查看不到第二块网卡的任何信息,并且/etc/sysconfig/network-scripts/目录也没有另一块网卡的配置文件。

[root@test ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:03:77:5D  
          inet addr:192.168.61.10  Bcast:192.168.61.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe03:775d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:75 errors:0 dropped:0 overruns:0 frame:0
          TX packets:52 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8798 (8.5 KiB)  TX bytes:6106 (5.9 KiB)
          Interrupt:19 Base address:0x2000 

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)

[root@test ~]# 
[root@test ~]# cd /etc/sysconfig/network-scripts/
[root@test network-scripts]# ls
ifcfg-eth0  ifdown-bnep  ifdown-ippp  ifdown-post    ifdown-sit     ifup-aliases  ifup-ib    ifup-isdn   ifup-post    ifup-sit       init.ipv6-global   network-functions-ipv6
ifcfg-lo    ifdown-eth   ifdown-ipv6  ifdown-ppp     ifdown-tunnel  ifup-bnep     ifup-ippp  ifup-plip   ifup-ppp     ifup-tunnel    net.hotplug
ifdown      ifdown-ib    ifdown-isdn  ifdown-routes  ifup           ifup-eth      ifup-ipv6  ifup-plusb  ifup-routes  ifup-wireless  network-functions

现需要在linux虚拟机里面配置一下,另一块网卡可用

[root@test network-scripts]# vim /etc/udev/rules.d/70-persistent-net.rules

# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:03:77:5d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:03:77:67", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
~                                                                                                                                                                                              
                                                                                                                                                                                           

查看以上配置文件,可以看到网卡信息,包括它的mac地址:

[root@test network-scripts]# cp ifcfg-eth0 ifcfg-eth1
[root@test network-scripts]# ls
ifcfg-eth0  ifdown       ifdown-ib    ifdown-isdn  ifdown-routes  ifup          ifup-eth   ifup-ipv6  ifup-plusb  ifup-routes  ifup-wireless     network-functions
ifcfg-eth1  ifdown-bnep  ifdown-ippp  ifdown-post  ifdown-sit     ifup-aliases  ifup-ib    ifup-isdn  ifup-post   ifup-sit     init.ipv6-global  network-functions-ipv6
ifcfg-lo    ifdown-eth   ifdown-ipv6  ifdown-ppp   ifdown-tunnel  ifup-bnep     ifup-ippp  ifup-plip  ifup-ppp    ifup-tunnel  net.hotplug
[root@test network-scripts]# 

复制第一块网卡 ifcfg-eth0的配置文件,重命名ifcfg-eth1

[root@test network-scripts]# vi ifcfg-eth1
DEVICE=eth1
HWADDR=00:0c:29:03:77:67
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.176.200
NETMASK=255.255.255.0
GATWAY=192.168.176.2
DNS1=222.222.222.222

更改ifcfg-eht1配置文件里面的HWADDR= 内容为,配置文件/etc/udev/rules.d/70-persistent-net.rules里面第二块网卡的MAC地址
别忘记其它参数:
DEVICE
IPADDR
NETMASK
GATWAY
DNS1 这里强调一下这里配置也DNS服务器后,就不用再去/etc/resolv.conf里面配置了,因为重启network服务后,这个值会自动写入到resolv.conf配置文件里面去

[root@test network-scripts]# cat /etc/resolv.conf

[root@test network-scripts]# vi ifcfg-eth1
[root@test network-scripts]# service network restart
正在关闭接口 eth0:                                        [确定]
正在关闭接口 eth1:                                        [确定]
关闭环回接口:                                             [确定]
弹出环回接口:                                             [确定]
弹出界面 eth0: Determining if ip address 192.168.61.10 is already in use for device eth0...
                                                           [确定]
弹出界面 eth1: Determining if ip address 192.168.176.200 is already in use for device eth1...
                                                           [确定]
[root@test network-scripts]# cat /etc/resolv.conf

nameserver 222.222.222.222
[root@test network-scripts]# 

为了固定使用地址,我把NAT模式的网卡的IP也使用了static。需要注意的是在配置IP 地址的时候要完全按照。VMware-编辑-虚拟网络编辑器里面的内容进行配置
如:网关应该用 NAT设置里面的网关】
IP地址应用使用 DHCP设置里面所规定的IP地址范围里面的IP 地址
在这里插入图片描述
因为我的虚拟机是双网卡,所以要上网的话,要定义一下出口网关

                                                           [确定]
[root@test network-scripts]# ping www.baidu.com
ping: unknown host www.baidu.com
[root@test network-scripts]# cat /etc/resolv.conf

nameserver 222.222.222.222

[root@test network-scripts]# route add -net 0.0.0.0/0 gw 192.168.176.2
[root@test network-scripts]# route -v
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.176.0   *               255.255.255.0   U     0      0        0 eth1
192.168.61.0    *               255.255.255.0   U     0      0        0 eth0
link-local      *               255.255.0.0     U     1002   0        0 eth0
link-local      *               255.255.0.0     U     1003   0        0 eth1
default         192.168.176.2   0.0.0.0         UG    0      0        0 eth1
[root@test network-scripts]# ping www.baidu.com
PING www.a.shifen.com (220.181.38.150) 56(84) bytes of data.
64 bytes from 220.181.38.150: icmp_seq=1 ttl=128 time=8.02 ms
64 bytes from 220.181.38.150: icmp_seq=2 ttl=128 time=7.56 ms
64 bytes from 220.181.38.150: icmp_seq=3 ttl=128 time=7.57 ms
64 bytes from 220.181.38.150: icmp_seq=4 ttl=128 time=7.87 ms
64 bytes from 220.181.38.150: icmp_seq=5 ttl=128 time=7.72 ms
^C
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4670ms
rtt min/avg/max/mdev = 7.564/7.751/8.027/0.194 ms
[root@test network-scripts]# 

刚刚定义的路由只是临时的,重启后就会失效,所以在定义永久的路由。

未完待续。。。。。

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值