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.

Changes after Foscam firmware upgrade

It took sometime for me to figure out what was going on.
It seems like after upgrading the firmware of Foscam camera to the latest,, "get_params.cgi" was gone. It is replaced with "get_status.cgi".

It looks like this:
$ wget -q -S -O -\?user=admin\&pwd=pass
  HTTP/1.1 200 OK
  Server: Boa/0.94.13
  Date: Tue, 11 Feb 2014 09:14:36 GMT
  Content-Type: text/plain
  Content-Length: 361
  Cache-Control: no-cache
  Connection: close
var id='00626E46F948';
var sys_ver='';
var app_ver='';
var alias='foscam01';
var now=1392110076;
var tz=28800;
var alarm_status=0;
var ddns_status=0;
var ddns_host='';
var oray_type=0;
var upnp_status=0;
var p2p_status=0;
var p2p_local_port=24937;
var msn_status=0;
var wifi_status=0;
var temperature=0.0;
var humidity=0;
var tridro_error='';
I don't know what else is changed.