Difference between revisions of "USB Internet"

From postmarketOS
Jump to: navigation, search
m (Fix a typo.)
Line 6: Line 6:
 
<syntaxhighlight lang="shell-session">
 
<syntaxhighlight lang="shell-session">
 
$ sudo route add default gw 172.16.42.2
 
$ sudo route add default gw 172.16.42.2
$ echo nameserver 8.8.8.8 | sudo tee /etc/resolv.conf
+
$ sudo echo nameserver 8.8.8.8 | sudo tee /etc/resolv.conf
 
Substitute 8.8.8.8 for your own internal DNS server if you want.
 
Substitute 8.8.8.8 for your own internal DNS server if you want.
 +
</syntaxhighlight>
 +
To make the configuration persistent after reboot do:
 +
<syntaxhighlight lang="shell-session">
 +
$ sudo echo 'route add default gw 172.16.42.2' > /etc/local.d/usb_internet.start
 +
$ sudo chmod +x /etc/local.d/usb_internet.start
 +
$ sudo rc-update add local
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 10:54, 21 January 2018

You can enable internet through the USB cable when WiFi doesn't work yet on your device. For this to work you set your host machine as gateway for your phone and let your host machine do network address translation for the phone.

On your phone:

$ sudo route add default gw 172.16.42.2
$ sudo echo nameserver 8.8.8.8 | sudo tee /etc/resolv.conf
Substitute 8.8.8.8 for your own internal DNS server if you want.

To make the configuration persistent after reboot do:

$ sudo echo 'route add default gw 172.16.42.2' > /etc/local.d/usb_internet.start
$ sudo chmod +x /etc/local.d/usb_internet.start
$ sudo rc-update add local

On the host machine:

$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward > /dev/null
$ sudo iptables -P FORWARD ACCEPT
$ sudo iptables -A POSTROUTING -t nat -j MASQUERADE -s 172.16.42.0/24

This will enable IPv4 forwarding on your host machine which basically lets it function as a router. The postrouting command will make the kernel on the host translate the packets between the phone network and your normal network on the host machine.

You can now verify the internet connection on your phone by pinging something. If this does not work it means you need to compile the kernel with USB_ETH setting enabled in menuconfig.