2

My RPi currently has a working 3G dongle and a Wifi dongle.

I followed this tutorial on how to set it up as an access point on wlan0 and modified it a bit so my NAT routes into the 3G modem (ppp0) instead of eth0. This part works fine.

I also have an apache server serving up a simple web page. This works if I plug in eth0 and punch in that IP address (192.168.1.8) into my browser. However this does not work if I'm connected to wlan0 and I punch in the address of my RPi (acting here as a router). I suspect this is because I'm redirecting all traffic from wlan0 to ppp0 but I still don't know how to work around it.

In short: How do I set up a web server on my existing RPi wifi access point?

> sudo iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 171 packets, 23295 bytes)
 pkts bytes target     prot opt in     out     source               destination 

Chain INPUT (policy ACCEPT 7 packets, 1387 bytes)
 pkts bytes target     prot opt in     out     source               destination 

Chain OUTPUT (policy ACCEPT 15 packets, 1102 bytes)
pkts bytes target     prot opt in     out     source               destination 

Chain POSTROUTING (policy ACCEPT 1 packets, 60 bytes)
 pkts bytes target     prot opt in     out     source               destination 
   62  3808 MASQUERADE  all  --  *      ppp0    0.0.0.0/0            0.0.0.0/0 

eth0 is my ethernet cable used for ssh'ing

> ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:f7:9d:14
          inet addr:192.168.1.8  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:184 errors:0 dropped:0 overruns:0 frame:0
          TX packets:136 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:17365 (16.9 KiB)  TX bytes:22840 (22.3 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:569 errors:0 dropped:0 overruns:0 frame:0
          TX packets:569 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:47694 (46.5 KiB)  TX bytes:47694 (46.5 KiB)

mon.wlan0 Link encap:UNSPEC  HWaddr 00-A1-B0-80-03-60-00-00-00-00-00-00-00-00-00-00
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:18024 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3892722 (3.7 MiB)  TX bytes:0 (0.0 B)

ppp0      Link encap:Point-to-Point Protocol
          inet addr:10.172.3.251  P-t-P:10.64.64.64  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1400  Metric:1
          RX packets:14321 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7634 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:19592815 (18.6 MiB)  TX bytes:348148 (339.9 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:a1:b0:80:03:60
          inet addr:192.168.42.1  Bcast:192.168.42.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7762 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14456 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:482698 (471.3 KiB)  TX bytes:20053576 (19.1 MiB)

EDIT:

> cat /etc/network/interfaces
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow hotplug wlan0

iface wlan0 inet static
  address 192.168.42.1
  netmask 255.255.255.0

#auto wlan0
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp

up iptables-restore < /etc/iptables.ipv4.nat

and

> sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
        ssid="NETGEAR"
        psk="<My company router's password>"
}
2
  • can you throw up your /etc/network/interfaces and /etc/wpa_supplicant/wpa_supplicant.conf files.
    – 11chubby11
    Commented Nov 1, 2013 at 2:10
  • updated my post
    – dudeofea
    Commented Nov 1, 2013 at 16:39

1 Answer 1

0

Fixed it with

sudo iptables -t nat -A PREROUTING -p tcp -d 192.168.42.1 --dport 80 -j REDIRECT --to-ports 8080

The result is

> sudo iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 5 packets, 637 bytes)
 pkts bytes target     prot opt in     out     source               destination
    5   300 REDIRECT   tcp  --  *      *       0.0.0.0/0            192.168.42.1             tcp dpt:80 redir ports 8080

Chain INPUT (policy ACCEPT 7 packets, 725 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 14 packets, 1026 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 1 packets, 60 bytes)
 pkts bytes target     prot opt in     out     source               destination
   16  1178 MASQUERADE  all  --  *      ppp0    0.0.0.0/0            0.0.0.0/0

I also moved my apache server to port 8080 just so I wouldn't have to deal with potential mess ups involving redirecting port 80 to port 80

1
  • When you can, remember to mark this as your answer :) Commented Feb 1, 2014 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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