# Raspberry Pi DHCP Server * Install network-manager ``` sudo apt-get install network-manager ``` * Enable network-manager ``` sudo service network-manager start ``` * Set up wifi wan ``` nmcli dev nmcli radio wifi on nmcli dev wifi list sudo nmcli dev wifi connect "network-ssid" password "network-password" ``` * if you can't find out the wifi list, you should try the way like the following * Edit the yaml file and delete the content and save. ``` sudo vim /etc/netplan/50-cloud-init.yaml ``` * Edit the NetworkManager.conf ``` cd /etc/NetworkManager/ vim NetworkManager.conf ``` * Make the managed = true ![](https://i.imgur.com/ZN9zVKK.png) ``` cd conf.d/ ls ``` ![](https://i.imgur.com/cz90FJV.png) * Add file named '10-globally-managed-devices.conf' and the content is 'unmanaged-devices=none' ![](https://i.imgur.com/IDU43Pk.png) * Then restart the NetworkManager ``` sudo systemctl restart NetworkManager netplan apply ``` * Create a bridge interface named 'brVLAN1' and the network interface card is brVLAN1 and the interface type is bridge ``` sudo nmcli con add ifname brVLAN1 type bridge con-name brVLAN1 nmcli connection show ``` * Create a bridge interface named 'brVLAN2' by **OVS** ``` sudo ovs-vsctl add-br brVLAN2 ``` * If occur error, you should delete the ${connect_name} like 'bridge-slave-x' ``` nmcli connection delete <CONNECTION_NAME> ``` * And readd the bridge ``` nmcli con add type bridge-slave ifname eth0 master brVLAN1 ``` * Add LAN port to 'brVLAN1' * ${x} is mean the connect LAN port like 'eth0' ``` nmcli con add type bridge-slave ifname ${x} master brVLAN1 ``` * Add LAN port to 'brVLAN2' by **OVS** ``` ovs-vsctl add-port brVLAN2 eth0 ``` * Install DHCP Server ``` apt install isc-dhcp-server ``` * Install iptables-persistent ``` sudo apt-get install iptables-persistent ``` * Set up DHCP Server ``` sudo vim /etc/dhcp/dhcpd.conf ``` * Add Ip Address to 'brVLAN1' ``` sudo nmcli connection modify brVLAN1 ipv4.addresses '192.168.0.1/24' sudo nmcli con modify brVLAN1 ipv4.method manual sudo nmcli con up brVLAN1 ``` * Add Ip Address to 'brVLAN2' by OVS ``` ip addr add 192.168.0.1/24 dev brVLAN2 ifconfig brVLAN2 up vim /etc/default/isc-dhcp-server ``` ![](https://i.imgur.com/5MPxptC.png) * Check the status of DHCP Server ``` systemctl status isc-dhcp-server ``` * The content of dhcpd.conf ``` option domain-name "example.org"; option domain-name-servers ns1.example.org, ns2.example.org; default-lease-time 600; max-lease-time 7200; ddns-update-style none; authoritative; subnet 192.168.0.0 netmask 255.255.255.0{ range 192.168.0.2 192.168.0.254; option routers 192.168.0.1; option subnet-mask 255.255.255.0; option broadcast-address 192.168.0.255; option domain-name-servers 8.8.8.8; default-lease-time 3600; max-lease-time 7200; } ``` * Restart DHCP Server setting ``` sudo systemctl restart isc-dhcp-server ``` * Iptables clean ``` # flush all chains iptables -F iptables -t nat -F iptables -t mangle -F # delete all chains iptables -X ``` * Add the rules of Nat * 'x.x.x.x/24' is mean the network segment like '192.168.0.0/24' ``` iptables -t nat -A POSTROUTING -s x.x.x.x/24 -o wlan0 -j MASQUERADE sudo vim /etc/sysctl.conf add "net.ipv4.ip_forward=1" sudo sysctl -p ``` * Save iptables setting ``` sudo dpkg-reconfigure iptables-persistent ```