把Linux服务器(工控机)变成交换机

很多人都见过这样的Linux主机,它有多个网口,长得像交换机。其实经过简单的配置,我们能够将该Linux主机当做交换机使用。

我的Linux工控机是基于Debian9.8的操作系统,共有4个网口:eth0 --> eth3。

实验网络环境如下图所示:

第一步:启动网络适配器
ifconfig eth0 up
ifconfig eth1 up
ifconfig eth2 up
ifconfig eth3 up

第二步:清除网络适配器的配置
ifconfig eth0 0.0.0.0
ifconfig eth1 0.0.0.0
ifconfig eth2 0.0.0.0
ifconfig eth3 0.0.0.0

第三步:新建一个网桥
brctl addbr br0

第四步:将网络适配器添加到网桥中
brctl addif br0 eth0
brctl addif br0 eth1
brctl addif br0 eth2
brctl addif br0 eth3

第五步:启动网桥
ifconfig br0 up

第六步:给网桥配置IP地址和子网掩码
ifconfig br0 192.168.1.5 netmask 255.255.255.0

第七步:设置默认网关

该网关要和上游路由器的默认网关保持一致

route add default gw 192.168.1.1

执行完上述命令后,该Linux工控机就变成了一个交换机。

猜你喜欢

转载自www.cnblogs.com/dgjnszf/p/10807148.html