I find this similar thread but don't work: https://stackoverflow.com/questions/10864854/forwarding-mysql-connection-with-iptables-and-differents-network-interfaces?rq=1
My environment as follows:
- Computer A has two network interfaces: eth0
192.168.42.67
and eth1192.168.110.2
, with MySQL client installed, selinux disabled. - Computer B has only one network interface: eth0
192.168.110.4
, with MySQL Server installed, iptables stopped, selinux disabled.
On Computer A , I use command mysql -h192.168.110.4 -uroot -p
connect to MySQL on Computer B successfully.
Computer A's /etc/sysconfig/iptables
looks as follows:
[root@net ~]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Mon Jun 9 20:25:07 2014
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1:140]
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
COMMIT
# Completed on Mon Jun 9 20:25:07 2014
# Generated by iptables-save v1.4.7 on Mon Jun 9 20:25:07 2014
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A PREROUTING -p tcp -m tcp --dport 3306 -j LOG --log-prefix "REX_NAT_PRE2:"
-A PREROUTING -p tcp -m tcp --dport 3306 -j DNAT --to-destination 192.168.110.4:3306
-A POSTROUTING -s 192.168.110.4/32 -j MASQUERADE
-A POSTROUTING -p tcp -j LOG --log-prefix "REX_NAT_POST:"
COMMIT
NOTE: I set default policy for every chain to ACCEPT
.
I hope i can use mysql -h192.168.42.67 -uroot -p
on Computer A to manipulate Computer B's MySQL
I have also executed modprobe iptable_nat
and echo 1 > /proc/sys/net/ipv4/ip_forward