User Controls

Two Wireless NIC - One For SSH/The Other For Internet

  1. #1
    SBTlauien African Astronaut
    I possess one of the Raspberry Pi's that have built in wifi. I have two wireless NICs attached to my Raspberry Pi(the internal NIC and one I attached). The internal NIC is wlan0 and the external is wlan1.

    I have the internal NIC(wlan0) set up to automatically connect to one of my phones hotspots. I then connect my PC to that phone and I SSH into my Raspberry Pi. This is how I want to access the Raspberry Pi.

    I'd like to be able to use the external NIC(wlan1) to connect to certain wifi hotspots and use them for the internet, while still using wlan0 for ssh(since that's how I'll be accessing it). These hotspot connections that wlan1 is connecting to may change from time to time.

    What type of iptable rules am I going to need to set to allow this to happen? I did a search and came across the following, but it doesn't seem to work

    iptables --flush
    iptables --delete-chain
    iptables --table nat --delete-chain

    iptables -P INPUT DROP
    iptables -P FORWARD DROP
    iptables -P OUTPUT DROP

    iptables -A INPUT -i wlan0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
    iptables -A OUTPUT -o wlan0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

    iptables --table nat --append POSTROUTING --out-interface wlan1 -j MASQUERADE

    echo 1 > /proc/sys/net/ipv4/ip_forward
    service iptables restart

    route add default gw 192.168.1.1 wlan1


    Here's some more information on my Raspberry Pi...

    $ifconfig
    lo        Link encap:Local Loopback  
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:65536 Metric:1
    RX packets:158 errors:0 dropped:0 overruns:0 frame:0
    TX packets:158 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1
    RX bytes:14100 (13.7 KiB) TX bytes:14100 (13.7 KiB)

    wlan0 Link encap:Ethernet HWaddr 12:12:12:12:13:13
    inet addr:192.168.43.211 Bcast:192.168.43.255 Mask:255.255.255.0
    inet6 addr: fe80::8b65:e176:2a95:75ea/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:5307 errors:0 dropped:662 overruns:0 frame:0
    TX packets:4497 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:539854 (527.2 KiB) TX bytes:1063866 (1.0 MiB)

    wlan1 Link encap:Ethernet HWaddr 12:12:12:12:11:11
    inet addr:192.168.43.112 Bcast:192.168.43.255 Mask:255.255.255.0
    inet6 addr: fe80::bd5b:a99c:1e0a:ab37/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:492 errors:0 dropped:0 overruns:0 frame:0
    TX packets:224 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:35039 (34.2 KiB) TX bytes:33749 (32.9 KiB)


    $cat /etc/network/interface
    auto lo

    iface lo inet loopback
    iface eth0 inet manual

    allow-hotplug wlan0
    iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

    allow-hotplug wlan1
    auto wlan1
    iface wlan1 inet dhcp
    wireless-essid someRandamWifiHotspot
    wireless-mode managed


    $cat /etc/wpa_supplicant/wpa_supplicant.conf
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    country=GB

    network={
    ssid="oneOfMyPhones"
    psk="anEasyPassword"
    key_mgmt=WPA-PSK
    }


    $route -n
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    0.0.0.0 192.168.43.1 0.0.0.0 UG 0 0 0 wlan1
    0.0.0.0 192.168.43.1 0.0.0.0 UG 302 0 0 wlan0
    0.0.0.0 192.168.43.1 0.0.0.0 UG 303 0 0 wlan1
    192.168.43.0 0.0.0.0 255.255.255.0 U 302 0 0 wlan0
    192.168.43.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan1
Jump to Top