第一步
修改/etc/sysctl.conf配置文件,以下两个选项的值默认是0的,修改为1
net.ipv4.ip_forward = 1
net.ipv4.conf.default.accept_source_route = 1
第二步,修改防火墙
方法一,用命令
1
2
3
4
5
|
iptables -t nat -A PREROUTING -d 127.0.0.1 -p tcp --dport 3306 -j DNAT --to-destination 192.168.1.X2:3306
iptables -t nat -A PREROUTING -d 192.168.1.X1 -p tcp --dport 3306 -j DNAT --to-destination 192.168.1.X2:3306
iptables -t nat -A POSTROUTING -j MASQUERADE
service iptables save
service iptables restart
|
方法二,直接改配置
1
2
3
4
5
6
|
vi /etc/sysconfig/iptables
-A PREROUTING -d 192.168.1.X1/32 -p tcp -m tcp --dport 3306 -j DNAT --to-destination 192.168.1.X2:3306
-A PREROUTING -d 127.0.0.1/32 -p tcp -m tcp --dport 3306 -j DNAT --to-destination 192.168.1.X2:3306
-A POSTROUTING -j MASQUERADE
service iptables save
service iptables restart
|