linux设置双网卡

linux设置双网卡,第1张

注意: 2 张网卡,只能有1张网卡配置网关,另1张网卡不能配置网关,通过route add 添加路由功能来完成第2张网卡的网关配置。

如 : eth1 (192.168.2.2)不需要配置网关, 但到 192.168.3.0 的网段,需要从eth1 去实现通信,其余的全部走eth0 网卡,eth0 配置 网关.

eth0 的配置如下,配置网关参数

[root@REDHAT network-scripts]# cat ifcfg-eth0

# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet

DEVICE=eth0

BOOTPROTO=none

ONBOOT=yes

HOTPLUG=no

TYPE=Ethernet

IPADDR=192.168.1.2

NETMASK=255.255.255.0

HWADDR=d8:d3:85:fb:d4:60

GATEWAY=192.168.1.1

USERCTL=no

IPV6INIT=no

PEERDNS=yes

eth1 的配置如下,不需要配置网关

[root@SERVER network-scripts]# cat ifcfg-eth1

# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet

DEVICE=eth1

BOOTPROTO=none

ONBOOT=yes

HOTPLUG=no

TYPE=Ethernet

IPADDR=192.168.2.2

NETMASK=255.255.255.0

USERCTL=no

IPV6INIT=no

PEERDNS=yes

Linux 命令行下添加路由,192.168.3.0 走 eth1 的网关 192.168.2.1

route add -net 192.168.3.0 netmask 255.255.255.0 dev eth1

如果可以init 5 到图形界面

可以在图形界面通过网络连接设置eth0、eth1

然后要断开连接,重新连接

init 3 下:

通过ifconfig 查看是否有eth1存在,如果不存在可能网线没连好,或是网卡不好用了。

如果有eth1 那就通过如下命令:

#ifconfig eth1 down

# ifconfig eth1 192.168.0.*

#route add -net 192.168.0.1

//添加路由(假设路由1是92.168.0)

#ifconfig eth1 up

有时这样还是不行,就重启下NetworkManager服务重启下

#server NetworkManager restart

linux中双网卡的梆定

创建一个bond设备,三个e5a48de588b6e799bee5baa6e997aee7ad9431333239313532简单的步骤即可搞定:

(1)首先要保证相应的驱动程序已经加载:

localhost@root

~#

modprobe

bonding

modprobe

<3c59x|

eepro100|pcnet32|tulip|...>

(2)其次给等梆定bond设备分配IP地址

localhost@root

~#

ifconfig

bond0

<IP地址>

netmask

<子网掩码>

broadcast

<广播地址

>

例如

ifconfig

bond0

192.168.1.242

netmask

255.255.255.0

broadcast

172.31.3.254

(3)最后将所有要梆定的物理网卡接口添加到bond设备中去

localhost@root

~#

ifenslave

bond0

[{-f|--force}

bond0

eth0

[

eth1

[eth2]...]

例如

ifenslave

bond0

eth0

eth1

梆定了eth0

eth1两个网卡设备。

--force

表示强制进行梆定

创建好bond设备后,就可以像一般的网卡设备一样使用了

如启动bond0:

#

ifconfig

bond0

up

停用bond0:

#

ifconfig

bond0

down

在不停用bond0的情况下添加接口:

#

ifenslave

{-d|

--detach}

bond0

eth0

[eth1

[eth2]...]

--detach表示"附加"的意思

改变活动的从设备:

#

ifenslave

{-c|--change-active}

bond0

eth0

--change-acitve

表示"改变活动的从设备"的意思

显示主接口(指bond0)信息:

#

ifenslave

bond0

显示所以接口信息:

#

ifenslave

{-a|--all-interfaces}

--all-interfaces

表示"所有接口"


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8897693.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-22
下一篇 2023-04-22

发表评论

登录后才能评论

评论列表(0条)

保存