2

I'm struggling to access the internet from my remote computer. I'd like to access the remote computer via ssh and have there the internet connection available to install packages etc.

It looks like this:

(Internet) <--wlan0--> ((Local Computer)) <--eth0--> ((Remote Computer))

On both computers Linux with Ubuntu trusty is running.
The IPs of the computers are:

Local Computer:

wlan0:  10.2.217.213
eth0:   192.168.1.10 (fixed)

Remote Computer:

eth0: 192.168.1.13 (fixed)

Can I just forward a port where I receive the connection to the internet on my local computer? How can I determine this port?

I'm glad for your help! I'm no network expert and already googled for hours and tried forwarding, bridging, sshuttle etc. with no success.

Thank you very much,
Jonas

  • Can the IP of remote computer be changed? – heemayl Apr 16 '15 at 9:48
  • It sounds, if you want a fairly simple solution, as if you want a proxy (e.g. Squid) running on "Local Computer"... if you had that, you could "tunnel" ssh over the proxy. There are, of course, more complicated solutions that would provide more transparent connectivity for "Remote Computer". – aSteve Apr 16 '15 at 9:54
2

Use this set of iptables rules to set up your local computer as a NAT router:

iptables -P INPUT DROP  # drop every INPUT
iptables -P FORWARD DROP    # drop every FORWARD
iptables -A INPUT -i lo -j ACCEPT   # accept loopback-INPUT
iptables -A INPUT -i eth0 -j ACCEPT # accept eth0 INPUT
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE   # NAT-Translation
iptables -A FORWARD -i eth0 -j ACCEPT   # accept FORWARD-Traffic from eth0
iptables -A FORWARD -i wlan0 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT # accept FORWARD-Traffic as reply for existing connections
iptables -A INPUT -i wlan0 -m state --state ESTABLISHED,RELATED -j ACCEPT # allow the local computer to access the internet
iptables -A INPUT -i wlan0 -p icmp --icmp-type echo-request -j ACCEPT # allow pings on wlan0
echo "1" > /proc/sys/net/ipv4/ip_forward

Do not copy these rules without checking them first. Use a root-Shell (e.g. sudo -s) to apply these rules to iptables.

Remember to set your local computer as gateway for the remote one.

  • This worked! Just had to use echo "1" | sudo tee /proc/sys/net/ipv4/ip_forward. Thank you – jonas- Apr 16 '15 at 12:39
  • yeah, if you just use sudo, it will be echoed as root, but written as the normal user. – Oliver R. Apr 16 '15 at 12:53
  • To access the remote computer via ssh you can consider opening a reverse tunnel with a ssh-session from the remote computer to another public computer (with a public ip): ssh -R 10000:127.0.0.1:22 user@public-host. To access the remote computer just do: ssh -p 10000 user@public-host – Oliver R. Apr 16 '15 at 13:01
  • with 'sudo' permission was denied – jonas- Apr 16 '15 at 13:08
0

Suggesting that both are linux machines you will have to set up routing on your local computer, that means at least setting this kernel parameter:

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

(This is a non permanent setting, it is gone after reboot. Put this line into /etc/rc.local for example to do this always on startup.)

The remote computer needs to have the local computer configured as his default gateway.

Depending on the configuration of your local computer, you might have to configure iptables to certain things, e.g. NAT. But basically this should not be needed. Furthermore the router between the internet and your local computer might need to know the route to the eth0-network (192.168.1.0/24 ?)

EDIT: I forgot the main thing: Assuming that you have a NAT router between the internet and the local computer and and you have set the route on that internet-router to your eth0-network, you can configure the portforwarding for ssh directly to 192.168.1.13.

I hope this helps!

  • Unfortunately I have no access to the router between internet and local computer. It is an university network. – jonas- Apr 16 '15 at 9:31
  • As your wlan0 address 10.2.217.213 originates from a private address space, direct SSH access to the remote computer will not be possible. But the remote computer can access the internet if you configure NAT by using iptables on the local computer. – Oliver R. Apr 16 '15 at 9:38
  • I tried to configure iptables for forwarding: sudo iptables -I FORWARD -i eth0 -o wlan0 -s 192.168.1.10/24 -d 10.2.217.213/24 -j ACCEPT and sudo iptables -I FORWARD -i wlan0 -o eth0 -s 10.2.217.213/24 -d 192.168.1.10/24 -j ACCEPT. But it has no effect and I don't now how to check for any effects. – jonas- Apr 16 '15 at 11:43
  • Direct forwarding will imho not work, because the internet router does not know about the 192.168.1.10/24 network behind your local computer. You need to masquerade the network packages you want to forward. Please check my second answer for this. – Oliver R. Apr 16 '15 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.