top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

port forwarding in Linux

+2 votes
297 views

I'm dealing with a issue involving port forwarding. I've got part of it working, trying to get the rest.

for now:
I have a serverside machine:
-runs the gearmand daemon on localhost port 4730
-runs the server.php - on ip localhost port 4730
-also runs the portforwarding which is created on the clientside to connect to localhost:4730
-the test server is runs on a machine as user foo@192.168.5.12

on the clientside machine
-runs the client.php - which runs on localhost port 4730
-also runs the ssh port forwarding process as follows
ssh -f -L - N 4730:localhost:4730 foo@192.168.5.12 -p 22
-the client is running on 192.168.5.14

Everything above works... I can run a serverside process, and the clientside workers get the data from the queue on localhost:4730

I'd like to be able to change the ip address of the gearman processes from localhost, to the actual ipaddress of the machine. This of course involves changing the port forwarding from the client to the server
machine.

posted Sep 20, 2013 by Amit Parthsarthi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

simple with a systemd-unit which also survives a reboot of the target machine because the command in ExecStart (which is *one* line including the port 22 of the forwarded service, in this case SSH of a internal machine) will fail in that case and the SSH command is executed 60 seconds later

/etc/sysconfig/forwarding contains the IP-address where the forwarding should listen instead 127.0.0.1, done this way because there is a fallback machine, more than one such services and so the systemd-units can be re-used

the result in short is 192.168.0.35:11025 is the forwarded 192.168.1.15:22 192.168.0.0/24 is a different subnet than 192.168.1.0/24, the numbers are generic to not disclose network-configurations, the files below are from a live-machine in all other parts

[root@localhost:~]$ cat /etc/sysconfig/forwarding
LOCAL_ADDRESS=192.168.0.35
________________________________________________

[root@localhost:~]$ cat /etc/systemd/system/forward-fileserver.service
[Unit]
Description=SSH-Forwarding Fileserver
After=network.service openvpn.service hostapd.service network-wlan-bridge.service network-bonding-bridge.service

[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/forwarding
ExecStart=/usr/bin/ssh -i /home/ssh-gateway/.ssh/id_rsa ssh-gateway@192.168.1.15 -N -C
-L${LOCAL_ADDRESS}:11025:127.0.0.1:22
Restart=always
RestartSec=60
TimeoutSec=30
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_DAC_OVERRIDE

[Install]
WantedBy=multi-user.target
answer Sep 22, 2013 by Sonu Jindal
Similar Questions
+1 vote

After testing and looking at the kernel source, I realize that this mapping:

iptables -t nat -I PREROUTING -p tcp -m tcp --dport 30000:40000 -j DNAT --to [local_ip]:10000-2000

Doesn't do a one-to-one port mapping
e.g.:

100.0.0.1:30000 > 192.168.0.5:10000
100.0.0.1.30001 > 192.168.0.5:10001
100.0.0.1.30002 > 192.168.0.5:10002

I was wondering if it was possible to do the 1:1 port range forwarding to different port ranges or if you have to use individual rules.

+3 votes

Trying to see if ssh/port forwarding can be used to solve a prob. I want to have multiple clients connected to a single master server

The masterServer/app is providing data on port X
The clientNodes/apps should then listen on port X

ssh allows for port forwarding, but I can't figure out how to accomplish this using ssh/port forwarding.

I've tried using :
ssh -L 8000:localhost:8000 bob@foo.com -p abc
as foo.com:abc is the vm ip/port that's the server app

I then did a test using nc where on the serverside, I did a nc -l 8000, and got an err msg indicating the port was already in use

Port 8000 is the port the server app sends data on, and is the port I'd like to listen on on the clientnodes/apps..

+2 votes

I have a IP configured which is not visible for another network (suppose IP: A).
I have a common machine/switch which is in between two networks, now need to set up IP forwarding such a way that the packets coming to IP: A should be forwarded to that machine correctly.

0 votes

Does anybody know if it makes a difference to enable IP forwarding on the (linux) host? I know both works (enabled or disabled), but is there a good choice regarding the use of virtio_net inside the (linux) guests?

...