lsgxeva

Linux开启路由转发功能

参考 https://www.cnblogs.com/highstar/p/3256813.html

参考 https://www.cnblogs.com/EasonJim/p/10206728.html

 

标记一下,今天想让一台 Red Hat Enterprise Linux 开通iptables的nat转发功能,找了半天。

A服务器:192.168.30.20/24

B服务器:192.168.30.1/24,eth0;  192.168.40.1/24,eth1

C服务器:192.168.40.20/24

目标:让A可以ping和ssh到c机器。这就需要通过B服务器来跳转。

操作过程:

1、在B服务器上开启内核路由转发参数

临时生效:

echo "1" > /proc/sys/net/ipv4/ip_forward

永久生效的话,需要修改sysctl.conf:

net.ipv4.ip_forward = 1

执行sysctl -p马上生效

2、B服务器开启iptables nat转发

iptables  -t nat  -A POSTROUTING  -s 192.168.30.0/24 -d 192.168.40.0/24 -o eth1 -j  MASQUERADE

# 配置源地址30网段,目标地址40网段的地址转换,从eth1网卡出。

iptables -t nat -A POSTROUTING -s 192.168.40.0/24  -d 192.168.30.0/24 -o eth0 -j MASQUERADE

#配置源地址40网段,目标地址30网段的地址转换,从eth0网卡出。

永久保存:iptables-save > /etc/sysconfig/iptables

TIP:注意对应网卡。

3、在A和C服务器上设置路由为B服务器IP

A:  route add -net 192.168.40.0 netmask 255.255.255.0 gw 192.168.30.1

C: route add -net 192.168.30.0 netmask 255.255.255.0 gw 192.168.40.1

 

============= End

 

分类:

技术点:

相关文章:

  • 2021-11-01
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2021-08-04
  • 2022-01-10
  • 2021-12-05
猜你喜欢
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2021-06-14
  • 2022-12-23
  • 2021-10-16
相关资源
相似解决方案