返回列表 发帖

CentOS6_配置双网卡

操心系统的版本信息:
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@localhost ~]#
[root@localhost ~]# uname -r
2.6.32-696.el6.x86_64


添加网卡后,重启network服务:
[root@localhost ~]# service network restart

先查看可用的网卡名:
[root@localhost ~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0C:29:2B:17:3A  
          inet addr:192.168.168.130  Bcast:192.168.168.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe2b:173a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:190 errors:0 dropped:0 overruns:0 frame:0
          TX packets:141 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:17302 (16.8 KiB)  TX bytes:19262 (18.8 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:14:DF:D5  
          BROADCAST MULTICAST  MTU:1500  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:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

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)


新网卡(eth1)可以立刻检测出来,但要创建配置文件:
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls ifcfg-*
ifcfg-eth0  ifcfg-lo
[root@localhost network-scripts]#
[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-eth1
[root@localhost network-scripts]#
[root@localhost network-scripts]# ls ifcfg-*
ifcfg-eth0  ifcfg-eth1  ifcfg-lo


原网卡(eth0)的配置文件:
[root@localhost network-scripts]# cat ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=1d6644ba-ea2f-47e9-af17-0119ea72d20b
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
HWADDR=00:0C:29:2B:17:3A
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
IPADDR=192.168.168.130
NETMASK=255.255.255.0
GATEWAY=192.168.168.2
DNS1=114.114.114.114
NAME="System eth0"



修改新网卡(eth1)的配置文件:
[root@localhost network-scripts]# cat ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
IPADDR=192.168.169.131
NETMASK=255.255.255.0
NAME="System eth1"

笺注:
文件里的eth0要改为eth1
UUID那行要删除;
HWADDR那行也要删除;
新网卡不用配置网关和DNS地址;
两张网卡理应使用不同的IP网段;


重启network服务:
[root@localhost ~]# service network restart


查看所有网卡的IP地址:
[root@localhost network-scripts]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:2B:17:3A  
          inet addr:192.168.168.130  Bcast:192.168.168.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe2b:173a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1154 errors:0 dropped:0 overruns:0 frame:0
          TX packets:365 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:90016 (87.9 KiB)  TX bytes:47090 (45.9 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:14:DF:D5  
          inet addr:192.168.169.131  Bcast:192.168.169.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe14:dfd5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11 errors:0 dropped:0 overruns:0 frame:0
          TX packets:29 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:870 (870.0 b)  TX bytes:1962 (1.9 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:4 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:408 (408.0 b)  TX bytes:408 (408.0 b)



至此,服务器既可以连接公网,也可以跟不同IP网段的主机进行通讯了:

[root@localhost ~]# ping -c3 www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39: icmp_seq=1 ttl=128 time=33.5 ms
64 bytes from 14.215.177.39: icmp_seq=2 ttl=128 time=47.8 ms
64 bytes from 14.215.177.39: icmp_seq=3 ttl=128 time=27.0 ms

--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2052ms
rtt min/avg/max/mdev = 27.090/36.162/47.807/8.651 ms


[root@localhost ~]# ping -c3 192.168.168.135
PING 192.168.168.135 (192.168.168.135) 56(84) bytes of data.
64 bytes from 192.168.168.135: icmp_seq=1 ttl=64 time=15.0 ms
64 bytes from 192.168.168.135: icmp_seq=2 ttl=64 time=1.72 ms
64 bytes from 192.168.168.135: icmp_seq=3 ttl=64 time=0.775 ms

--- 192.168.168.135 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2029ms
rtt min/avg/max/mdev = 0.775/5.841/15.019/6.501 ms


[root@localhost ~]# ping -c3 192.168.169.136
PING 192.168.169.136 (192.168.169.136) 56(84) bytes of data.
64 bytes from 192.168.169.136: icmp_seq=1 ttl=128 time=16.0 ms
64 bytes from 192.168.169.136: icmp_seq=2 ttl=128 time=0.969 ms
64 bytes from 192.168.169.136: icmp_seq=3 ttl=128 time=0.835 ms

--- 192.168.169.136 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2013ms
rtt min/avg/max/mdev = 0.835/5.945/16.033/7.133 ms





相关文章:
CentOS6_网络基础

CentOS7_配置双网卡
CentOS8_配置双网卡可参考:ESXI6.5_虚拟机端口组

返回列表