Ubuntu 20 or 22 Network Router (Bridge) Configuration with NetPlan

Mindwatering Incorporated

Author: Tripp W Black

Created: 02/27/2023 at 04:46 PM

 

Category:
Ubuntu
Configuration Files

Task:

Set-up an Ubuntu workstation as a network bridge.
If you are not comfortable w/a console/terminal prompt, and would prefer a graphical interface, install the regular Ubuntu workstation software rather than the minimal Ubuntu server.

That said, if you choose the graphical workstation, you will still need to do the bridge configuration "by hand" via terminal.

Assumptions:
These instructions assume:
- the workstation is set-up with the network management using NetPlan (networking system software) vs. systemd
- that the ISP, if the network gateways are ISP managed, are both (one for each network) willing to add a "static route"
- that the workstation has two network cards, and one is connected to the first internal network (LAN1) and the other is connected to the second internal network (LAN2).
- that the workstation will get its network address/IP dynamically via DHCP4.
- For this example, the following networking environment exists
LAN1 - 10.0.1.0/24
LAN2 - 192.168.1.0/24
LAN1 Gateway - 10.0.1.1
LAN2 Gateway - 192.168.1.1
- For this example, the following NIC (network interface cards/ports) are in the workstation
PC NIC1 = ens160, with static IP of 10.0.1.30
PC NIC2 = ens162, with static IP of 192.168.1.30
- The primary user is My Admin, with the login myadmin, that is set-up during the installation.

1. Install Ubuntu
Insert the appropriate "Live" DVD or use the appropriate disk image/ISO file.
If using the minimal server installation, ensure the install SSH is left checked (enabled) for remote network access this workstation from other workstations on the LAN.

2. After your installation, login as your primary user, myadmin confirm your network addresses.
Open a Terminal window, and enter the following command.
$ ip address
<view output, ignore the local loopback, lo interface >
. . .
2. ens160: ...
...
inet 10.0.1.nn ...
3. ens162: ...
inet 192.168.1.nn ...

Notes:
- Both NICs are likely to have the DHCP addresses assigned by each of the two network gateways.
- Current this workstation has access to both networks, and can browse, use printers, etc. on both. However, neither of the workstations on either network know how to get to the "other" network.


3. Update the installation to switch the workstation to routing (technically bridging is one LAN subset) mode.
a. In the existing Terminal window locate the NetPlan networking file.
$ cd /etc/NetPlan/
$ ls
<view output>
01-network-manager-all.yaml

Note:
- The filename may vary. Use the filename above for the next step below.

b. Edit the file, use the sequence <esc>:wq to save the change. Use <i> to insert new text.
$ sudo vi /etc/netplan/01-network-manager-all.yaml
network:
version: 2
renderer: networkd
ethernets:
ens160:
addresses:
- 10.0.1.30/24
dhcp4: no
routes:
- to: 10.0.1.0/24
via: 10.0.1.1
table: 101
routing-policy:
- from: 10.0.1.0/24
table: 101
ens162:
addresses:
- 192.168.1.24/24
dhcp4: no
routes:
- to: default
via: 192.168.1.1
- to: 192.168.1.0/24
via: 192.168.1.1
table: 102
routing-policy:
- from: 192.168.1.0/24
table: 102

c. Restart the network:
$ sudo systemctl restart network


4. Disable the firewall:
$ sudo ufw status
<view output>

If not already disabled, disable the UFW firewall service with:
$ sudo ufw disable


In the YAML above, we created static routes for each of the NICs/gateways, add a static route on each gateway to route through this new workstation.
- From the 192.168.1.0/24 gateway, set the static route to the 10.0.1.0/24 network to go via (through) 192.168.1.30
- From the 10.0.1.0/24 gateway, set the static route to the 192.168.1.0/24 network to go via (through) 10.0.1.30

$ sudo netplan try
<review for errors>

$ sudo netplan apply



5. Test from other workstations on either side.





previous page