0

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 49.225.37.106 as shown below.

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
    inet 127.0.0.1  netmask 255.0.0.0
    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

ppp0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
    inet 49.225.37.106  netmask 255.255.255.255  destination 10.64.64.64
    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 10.10.10.100  netmask 255.255.255.0  broadcast 10.10.10.255
    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
address 10.10.10.185
netmask 255.255.255.0
gateway 49.225.188.178 

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 10.64.64.64 dev ppp0
[11:31:42] openhabian@openHABianPi:~$ sudo route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.64.64.64     0.0.0.0         UG    0      0        0 ppp0
10.10.10.0      0.0.0.0         255.255.255.0   U     0      0        0 wlan0
10.64.64.64     0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
link-local      0.0.0.0         255.255.0.0     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 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 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 at 12:22
  • @Ingo, I am using openhabian. – Beedee Mar 3 at 19:42
  • Guys, solved it this morning. Cheers! – Beedee Mar 3 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.