This is a continuation of Last time. This is what I want to do for the time being.
This time, "Make Raspberry Pi a router".
-[1] Obtain a domain using GCP and MyDNS -[2] Set up Softether Server on GCP (Connect from iPhone / Raspberry Pi) -[3] Reverse proxy from Apache on GCP to local Raspberry Apache -[4] Make Raspberry Pi a router -[5] Create a Python script for Wake on LAN.
Since there is only one LAN port on Raspberry Pi, I will write a wired LAN adapter. Like this guy.
If you check with the ʻip a command (
sudo ifconfig), a new Ethernet Ineterface should be added. This time it was named ʻeth1
.
$ sudo ifconfig #ip a seems to be better
eth1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 04:ab:18:3b:af:e2 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Assign a fixed IP. This time, I want to create a new network (192.168.1.0/24
) using Raspberry Pi as a router * as shown in the figure below.
sudo vi /etc/dhcpcd.conf
Add the following.
/etc/dhcpcd.conf
# External ethernet
interface eth1
static ip_address=192.168.1.1/24 # you can assign arbitrary ip address and subnet mask. Note that client must designate this address as gateway
static routers=**.**.**.** # you can assign arbitrary ip too. if this server's network is from another router, set routers address may be better.(you will not need to set dns masquerade)
static domain_name_servers=8.8.8.8 # see above line's comment
**. **. **. **
of ↑, and the public address of Google is entered in the dns address. (Maybe it's not a router anymore ... I don't know because I'm not familiar with it lol)**. **. **. **
and comment out the dns address? .. And, as you can see, should I set up the DNS masquerade and DHCP server? .. ..When you turn on the power of the desktop PC connected to Raspberry Pi and check the ip, IP is assigned to ʻeth1`.
sudo ifconfig # or ip a
# eth1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
# inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255
# ether **:**:**:**:**:** txqueuelen 1000 (Ethernet)
# RX packets 0 bytes 0 (0.0 B)
# RX errors 0 dropped 0 overruns 0 frame 0
# TX packets 0 bytes 0 (0.0 B)
# TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ping 192.168.1.**
Set the IP masquerade. 1st line: Allow transfer from private IP address space to -o. 2nd line: SNAT. Line 3: DNAT.
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT # SNAT
sudo iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT # DNAT
If this is left as it is, it will be temporary and the information will be lost when you restart.
mkdir ~/iptable && cd ~/iptable
sudo iptables-save > iptables.dat
sudo vi /etc/rc.local
/etc/rc.local
# iptables
iptables-restore < /home/{user name}/iptable/iptables.dat
Your desktop PC should now be connected to the Internet.
Making a router on Ubuntu 16.04 Building a NAT router on Ubuntu 18.04 LTS How to turn a Linux machine into a router Add a USB-LAN adapter to your Ubuntu to make it a router Try to build a new LAN using Ubuntu PC as a router How to Setup a Raspberry Pi DNS Server Install Dnsmasq on Raspberry Pi
Recommended Posts