I am using openhabian. I have managed to get the Pi connected to the internet via the Quectel UC20-G modem after which I get a new interface called ppp0 with IP address as shown below.

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
    inet  netmask
    inet6 ::1  prefixlen 128  scopeid 0x10<host>
    loop  txqueuelen 1000  (Local Loopback)
    RX packets 57  bytes 4138 (4.0 KiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 57  bytes 4138 (4.0 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    inet  netmask  destination
    ppp  txqueuelen 3  (Point-to-Point Protocol)
    RX packets 5  bytes 55 (55.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 4  bytes 58 (58.0 B)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet  netmask  broadcast
    inet6 fe80::ba27:ebff:fe95:2b41  prefixlen 64  scopeid 0x20<link>
    ether b8:27:eb:95:2b:41  txqueuelen 1000  (Ethernet)
    RX packets 2686  bytes 577086 (563.5 KiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 562  bytes 102198 (99.8 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Now I'd like to connect my PC to the Pi via Ethernet port and access the internet that the Pi uses via ppp0. I did some research online and performed the below steps.

First I edited the interfaces file (/etc/network/interfaces) as shown below:

source-directory /etc/network/interfaces.d

auto lo

iface lo inet loopback

iface eth0 inet static

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

In the above, the address is the static ip to the eth0 and gateway is the ip address of the Pi at ppp0.

After this I ran the following commands with the Ethernet of my PC connected to the Pi.

[11:24:28] openhabian@openHABianPi:~$ sudo route del default
[11:31:22] openhabian@openHABianPi:~$ sudo route add default gw dev ppp0
[11:31:42] openhabian@openHABianPi:~$ sudo route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         UG    0      0        0 ppp0   U     0      0        0 wlan0 UH    0      0        0 ppp0
link-local     U     1000   0        0 wlan0

Then ran some iptables commands as below.

[11:34:15] openhabian@openHABianPi:~$ sudo sysctl net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1
[11:34:20] openhabian@openHABianPi:~$ sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
[11:34:32] openhabian@openHABianPi:~$ sudo iptables -A FORWARD -i eth0 -o ppp0 -m state --state RELATED,ESTABLISHED -j ACCEPT
[11:34:36] openhabian@openHABianPi:~$ sudo iptables -A FORWARD -i ppp0 -o eth0 -j ACCEPT
[11:34:44] openhabian@openHABianPi:~$ sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

After doing the above, I am still not getting internet on my PC from the Pi. Can someone please guide me with this to getting this working.

  • 3
    Why do you think the file contains "# Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' "? Why dou want to set a static IP-address in the first place? What you "research online" is obsolete and has broken networking. See How to set up networking/WiFi – Milliways Feb 28 '19 at 23:19
  • I need to set it static because we are going to connect KNX to the pi's Ethernet port. – Beedee Mar 1 '19 at 0:30
  • What operating system do you use? Because you use /etc/network/interfaces for your network setup it cannot be Raspbian? Please address me with @Ingo, otherwise I won't see your reply. – Ingo Mar 1 '19 at 12:22
  • @Ingo, I am using openhabian. – Beedee Mar 3 '19 at 19:42
  • Guys, solved it this morning. Cheers! – Beedee Mar 3 '19 at 23:55

Your Answer

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

Browse other questions tagged or ask your own question.