Feb 11, 2014

Foscam and Raspberry IP network sharing with wired LAN

I spent sometime to get this working and I want to share what I figured. I wanted to set a Raspberry Pi to be a network sharing device.

The setting was (a) Foscam IP camera is connected to (b) Raspberry Pi with eth0 wired LAN cable. And (b) the Raspberry Pi is connected to internet via wifi, wlan0.

I wanted to access web port of (a) Foscam IP camera via a port, 80, on (b) Raspberry Pi.

Here is MASQUERADE setting that should be stored in /etc/rc.local. The IP address of (a) Foscam IP camera in this setting is
# Enable ip forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Clear all existing iptables rules
/sbin/iptables -F
/sbin/iptables -t nat -F
/sbin/iptables -t mangle -F

# Create new rules for routing between your wireless and wired connection
/sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
/sbin/iptables -A FORWARD -i wlan0 -p tcp --dport 80 -d -j ACCEPT
/sbin/iptables -A FORWARD -i wlan0 -o eth0 -m state   --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
/sbin/iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 80 -j DNAT --to

This setting is learned from a website, here.


Jonatan Garces Lara said...

Hi! I want the same thing, connect my ip camera hikvision rtsp protocol
the masquerade where do i save it and with that name ? or the
file located in /etc/rc.local i add the script of above?

Gilson said...

Hi Jay,

Tried to follow your instructions but could not even connect to the Raspberry through wifi with the IP camera connected to Eth0. Is the cable a regular ethernet cable?

Jay said...

Hi Gilson, I think I know what your problem is. You need to use "crossover cable" not the usual network cable.

You can also use adapters like this: http://www.amazon.com/Cables-Unlimited-Cat6-Crossover-Adapter/dp/B00030BYJI/ref=sr_1_2?ie=UTF8&qid=1394905184&sr=8-2&keywords=cross+cable