0

I have Raspberry Pi connected with PC on eth0 port. I am using eth0 to ssh RPi. I have web application on RPi that requires Internet access.

Now, I set static ip to RPi (192.168.1.50) and to PC (192.168.1.66). I can connect to Internet through wireless adapter on PC and also through USB Wi-Pi adapter on RPi.

Here is PC's ifconfig:

eth0      Link encap:Ethernet  HWaddr 3c:a8:2a:7e:fd:7d  
          inet addr:192.168.1.66  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::3ea8:2aff:fe7e:fd7d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:184 errors:0 dropped:0 overruns:0 frame:0
          TX packets:638 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:20422 (20.4 KB)  TX bytes:80928 (80.9 KB)

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:4126 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4126 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:460006 (460.0 KB)  TX bytes:460006 (460.0 KB)

wlan0     Link encap:Ethernet  HWaddr 34:e6:ad:08:67:5e  
          inet addr:192.168.1.13  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::36e6:adff:fe08:675e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11305 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10338 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:6496258 (6.4 MB)  TX bytes:1391363 (1.3 MB)

When I connect to Internet on RPi, wlan0 gets 192.168.1.10.

The problem is, when I ssh through PC to RPi, I don't have Internet access on RPi and route -n shows eth0 as prefered interface.

I am trying to bridge wireless and ethernet connection, either on PC and to share Internet to RPi while doing ssh, or to bridge connections on RPi, so I could have wlan0 and eth0 active at the same time.

I tried to echo 1 > /proc/sys/net/ipv4/ip_forward, and also used MASQUERADE option on iptables, but with no success. I am missing something, and doing something wrong but can't actually see it.

Can you explain to me how can I achieve my goal here, how to set up /etc/network/interfaces file and anything else that I should consider?

Thank you.

1

With commands: https://wiki.debian.org/BridgeNetworkConnections (Wireless in mid)

Install bridge-utils:

apt-get install bridge-utils (ubuntu)

aptitude install bridge-utils (debain)

nano /etc/network/interfaces 

add below lines

pre-up iwconfig wlan0 essid $YOUR_ESSID (wifi name)

bridge_hw $MAC_ADDRESS_OF_YOUR_WIRELESS_CARD(34:e6:ad:08:67:5e)

Install ebtables:

aptitude install ebtables (debian)

apt-get install ebtables (ubuntu)

setup bridge network with wlan0 MAC address($MAC=34:e6:ad:08:67:5e)

ebtables -t nat -A POSTROUTING -o wlan0 -j snat --to-src $MAC --snat-arp --snat-target ACCEPT

Add device MAC address which need internet access:(replace $ip with ip, $MAC with MAC address of pi and computer)

Set rules :

ebtables -t nat -A PREROUTING -p IPv4 -i wlan0 --ip-dst $IP -j dnat --to-dst $MAC --dnat-target ACCEPT
ebtables -t nat -A PREROUTING -p ARP -i wlan0 --arp-ip-dst $IP -j dnat --to-dst $MAC --dnat-target ACCEPT

Repeat the above command for adding both pi and computer.

Save rules:

EBTABLES_ATOMIC_FILE=/root/ebtables-atomic ebtables -t nat --atomic-save

EBTABLES_ATOMIC_FILE=/root/ebtables-atomic ebtables -t nat --atomic-commit

With GUI: https://askubuntu.com/questions/359856/share-wireless-internet-connection-through-ethernet

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – jasonwryan Feb 6 '16 at 19:52
  • @jasonwryan answer updated with command. – editinit Feb 6 '16 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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