You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a question regarding Redsocks and iptables rules. Following is the scenario.
I have two servers server1 - 172.17.0.1, server2 - 172.17.0.2. I need to access JMX port (7199) on server1 from server2. Since I have disabled remote JMX on server1, I cannot access it from server2 via SSH local forwarding(need to access 7199 port with localhost from server2). So I have created SSH socks proxy and configured it with Redsocks. It's working fine.
# run socks proxy from service2
ssh -v -N -D 9999 user@172.17.0.1
# configure socks proxy with Redsocks in service2
redsocks {
// redsocks listening port
local_ip = 127.0.0.1;
local_port = 12345;
// socks proxy
ip = 127.0.0.1;
port = 9999;
type = socks5;
}
# configure iptable rules to route the packets to Redsocks in service2
sudo iptables -t nat -N REDSOCKS
sudo iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 12345
sudo iptables -t nat -A OUTPUT -p tcp --dport 7199 -j REDSOCKS
sudo iptables -t nat -A OUTPUT -p tcp -m owner --uid-owner <user id> -j REDSOCKS
Now if I connect to the 127.0.0.1:7199 from service2(e.g telnet localhost 7199) it will connect to the JMX port(7199) of server1. Redsocks route packets correctly to the server1 via socks proxy.
I have another requirement. When coming packets with IP address of the service1(e.g 172.17.0.1:7199), I need to redirect them to localhost(127.0.0.1:7199). For an example, if I connect with 172.17.0.1:7199 from service2, I need to redirect it to 127.0.0.1:7199 in order to access the JMX port in service1 via socks proxy. Normally IP address redirection can be done with one of the following iptables rules. Since there are other iptables rules existing(related to Redsocks) it does not work.
# redirect with host
iptables -t nat -A OUTPUT -p tcp -d 172.17.0.1 -j DNAT --to-destination 127.0.0.1
# redirect with host and port
iptables -t nat -A OUTPUT -p tcp -d 172.17.0.1 --dport 7199 -j DNAT --to-destination 127.0.0.1:7199
How IP address redirection to localhost can be done in this scenario?
The text was updated successfully, but these errors were encountered:
This is a question regarding Redsocks and iptables rules. Following is the scenario.
I have two servers
server1 - 172.17.0.1
,server2 - 172.17.0.2
. I need to accessJMX
port (7199
) onserver1
fromserver2
. Since I have disabled remote JMX onserver1
, I cannot access it fromserver2
via SSH local forwarding(need to access7199
port withlocalhost
fromserver2
). So I have created SSH socks proxy and configured it with Redsocks. It's working fine.Now if I connect to the
127.0.0.1:7199
fromservice2
(e.gtelnet localhost 7199
) it will connect to the JMX port(7199
) ofserver1
. Redsocks route packets correctly to theserver1
via socks proxy.I have another requirement. When coming packets with IP address of the
service1
(e.g172.17.0.1:7199
), I need to redirect them to localhost(127.0.0.1:7199
). For an example, if I connect with172.17.0.1:7199
fromservice2
, I need to redirect it to127.0.0.1:7199
in order to access the JMX port inservice1
via socks proxy. Normally IP address redirection can be done with one of the followingiptables
rules. Since there are otheriptables
rules existing(related to Redsocks) it does not work.How IP address redirection to
localhost
can be done in this scenario?The text was updated successfully, but these errors were encountered: