pbukowski
Posts: 3
Joined: Sun Sep 18, 2016 10:46 pm

ssh breaks after Port Forwarding

Sun Sep 18, 2016 11:11 pm

Hi,

I have setup my Raspberry Pi 3 as an additional router in my house. The goal was to allow it to work as a Wireless Access Point, so that people who connect to it, can surf the internet. I followed the latest instructions to do that and that part works fine.

Part of the instructions require me to make changes inside this config file:
sudo nano /etc/network/interfaces

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.201 (1 higher than the ethernet port)
netmask 255.255.255.0
network 192.168.0.200
broadcast 192.168.0.255
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

up sysctl -w net.ipv4.ip_forward=1


# restart hostapd and dnsmasq
   up /etc/init.d/hostapd restart
    up /etc/init.d/dnsmasq restart


After rebooting which runs the above code, it breaks my ssh ability (using Putty). I am attempting to connect to the pi from my main router inside my local network. The Pi has it's eth0 set to static 192.168.0.200. It also has it's wlan0 set to static 192.168.0.201. My main router which stands between the pi and the internet has static 192.168.0.2. As I attempt to initiate the ssh connection, it just hangs and eventually times out. If I remove the sudo iptables commands from inside the above file, I am able to successfully connect with ssh.

Can anyone please help me to correct the problem?

Thanks !
Paul

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: ssh breaks after Port Forwarding

Mon Sep 19, 2016 1:07 am

If you're running Raspbian Jessie then that stuff you've added to /etc/network/interfaces will break your networking. Add static IP defintions to /etc/dhcpcd.conf

Code: Select all

interface eth0
static ip_address=192.168.0.201/24
static routers=192.168.0.254
static domain_name_servers=192.168.0.254 8.8.8.8
#
interface wlan0
static routers=192.168.0.254
static domain_name_servers=192.168.0.254 8.8.8.8
static domain_search=example.co.uk
static ip_address=192.168.0.202/24
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pbukowski
Posts: 3
Joined: Sun Sep 18, 2016 10:46 pm

Re: ssh breaks after Port Forwarding

Mon Sep 19, 2016 1:24 am

I am indeed running Jessie. The instructions stated to apply the commands within that file.

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: ssh breaks after Port Forwarding

Mon Sep 19, 2016 7:37 am

The comment lines at the top of /etc/network/interfaces in Jessie trump those old instructions you followed.
Quis custodiet ipsos custodes?

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: ssh breaks after Port Forwarding

Mon Sep 19, 2016 10:16 am

pbukowski wrote:I am indeed running Jessie. The instructions stated to apply the commands within that file.
Undo your changes and do it properly using the September 2015 (and beyond) instructions not the old out of date stuff from 2014 (or before). Networking and the instructions for setting a static IP address changed with Raspbian Jessie. That came out a year ago.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: ssh breaks after Port Forwarding

Mon Sep 19, 2016 10:50 am

pbukowski wrote: I have setup my Raspberry Pi 3 as an additional router in my house. The goal was to allow it to work as a Wireless Access Point,
Wireless access point often means a bridged network connection (i.e. the wifi devices are on the same subnet as the wired interface). Router implies that the two interfaces are on different networks
pbukowski wrote: allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.201 (1 higher than the ethernet port)
netmask 255.255.255.0
network 192.168.0.200
broadcast 192.168.0.255
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
As well as the comments others have made about editing the right files.
If this is a routed subnet then the addresses should be on different networks i.e. you should change the 3rd digit.

You're network address is also wrong, the network address is the very first address on the network (with the broadcast being the very last address). You shouldn't normally need to specify these however for a device with an address of 192.168.0.201/24 the network address would be 192.168.0.0 and the broadcast is 192.168.0.255 ( the /24 is an alternative way of writing 255.255.255.0 as the subnet mask)

I'd suggest setting the wlan interface as something like 192.168.1.254 (if you want to configure them the network address is 192.168.1.0 and broadcast 192.168.1.255). You'll then need to update any dhcp server you setup on the Pi (dnsmasq) to give out addresses in the 192.168.1.0 range.

pbukowski
Posts: 3
Joined: Sun Sep 18, 2016 10:46 pm

Re: ssh breaks after Port Forwarding

Mon Sep 19, 2016 1:28 pm

Thanks everyone for all the suggestions. I will try again tonight and will let you know if it works ok.

Return to “Troubleshooting”