网络配置拾遗

网络配置拾遗

一、网桥设置

将设备中的两个网卡桥接

ifconfig eth0 0.0.0.0 up
ifconfig eth1 0.0.0.0 up
btctl addbr br0
brctl addif br0 eth0
brctl addif br0 eth1
ifconfig br0 192.168.10.1 up

桥接的两个网卡不设置ip,只需给网桥设置ip

二、设备中有两个网卡,当两个网卡设置同网段不同ip时(192.168.10.11、192.168.10.22),只有一个网卡能ping通

因为系统只从其中一张网卡获取网关,其他网卡来的ICMP请求包,会被系统过滤掉。

1、可以关闭反向路由检查防止系统过滤:

echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/eth1/rp_filter

2、可以把两个网卡分到2个不同的路由表中

echo "210 table0" >> /etc/iproute2/rt_tables
echo "211 table1" >> /etc/iproute2/rt_tables
ip route flush table table0
ip route flush table table1
ip route add 192.168.10.0/24 dev eth0 src 192.168.10.11 table table0
ip route add 192.168.10.0/24 dev eth1 src 192.168.10.22 table table1
ip route add default dev eth0 via 192.168.10.1 table table0
ip route add default dev eth1 via 192.168.10.1 table table1
ip rule add from 192.168.10.11 table table0
ip rule add from 192.168.10.22 table table1

三、NAT路由转发

参考自https://www.latelee.org/using-gnu-linux/iptables-note-outside-to-inside.html

设备A有两张网卡eth0和eth1,eth0接外网,eth1(192.168.10.1)接内网设备B(192.168.10.2),
eth0和eth1不同网段。现把从eth0收到的包,通过eth1转发到设备B。

1、转发特定端口包

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 22 -j DNAT --to 192.168.10.2:22
iptables -t nat -A POSTROUTING -o eth1 -d 192.168.10.2 -p tcp --dport 22 -j SNAT --to 192.168.10.1

2、转发所有包

iptables -t nat -A PREROUTING -i eth0 -p tcp -j DNAT --to 192.168.10.2
iptables -t nat -A POSTROUTING -o eth1 -d 192.168.10.2 -p tcp -j SNAT --to 192.168.10.1
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值