Ubuntu Router Sample
$ ip link show
1: lo: ...
2. ens160: ...
3. ens192: ...
The command gives each interface name followed by some important information including the MAC address. As the network interfaces do not show up in the /dev/ system view, we use this command to print out the invoices, confirm their MAC address to the VM Ethernet
There are two commands to view the IP addresses, both work well.
$ ip address show
or
$ ifconfig
Add the ethernet adapter to view configuration on just the one of interest:
$ ifconfig ens192
If you are updating an interface for jumbo frames, you can use:
$ sudo ip link set ens192 mtu 9000
or
Edit the /etc/network/interfaces/ file directly:
(Swap out "x" with your primary IP subnet, swap out "n" with your second IP subnet, replace the 123.123.123.123 with your secondary DNS server, etc. )
$ sudo vi /etc/network/interfaces:
auto ens160
iface ens160 inet static
address 192.168.x.123
netmask 255.255.255.0
network 192.168.x.0
broadcast 192.168.x.255
gateway 192.168.x.1
mtu 9000
dns-nameservers 192.168.x.1 123.123.123.123
dns-search mindwatering.internal mindwatering.com
auto ens192
iface ens192 inet static
address 10.0.n.123
netmask 255.255.255.0
network 10.0.n.0
mtu 9000
post-up ip route add 192.168.n.0/24 dev ens192 src 192.168.n.123 table rt2
post-up ip route add default via 192.168.n.1 dev ens192 table rt2
post-up ip rule add from 192.168.n.123/32 table rt2
post-up ip rule add to 192.168.n.123/32 table rt2
<esc :wq>
$ sudo systemctl restart networking
Note:
Don't enter a gateway for the second interface or you'll get a "RTNETLINK File exists" error.
To make the router forward between interfaces, we need to edit the /etc/sysctl.conf configuration file:
$ sudo vi /etc/sysctl.conf
Uncomment the line, below. If you using IP6, uncomment its line, as well.
# net.ipv4.ip forward=1
to
net.ipv4.ip forward=1
<esc :wq>
To make the router route between interfaces, we need to edit the /etc/iproute2/rt_tables configuration file with the route entries we added to the interface:
$ sudo vi /etc/iproute2/rt_tables
Below the #1 inr,ruhep example line, add the following swapping out the "n" again for your IP subnet.
#1 inr.ruhep
# static route added for second interface ens192 from ens160
# with specification of gateway for second network
# the two rules specify that all traffic for that network go through ens192
1 rt2
ip route add 192.168.n.0/24 dev ens192 src 192.168.n.123 table rt2
ip route add default via 192.168.n.1 dev ens192 table rt2
ip rule add from 192.168.n.123/32 table rt2
ip rule add to 192.168.n.123/32 table rt2
To monitor and troubleshoot connections, install iptraf-ng, bmon or tcptrack.
e.g.
$ sudo apt-get install iptraf-ng
Monitor an interface like:
$ sudo iptraf-ng
Misc. Notes:
If you were not doing forwarding, and just needed a static route, the /etc/network/interfaces entries would look like below. The first uses a gateway, the other uses a connected interface.
up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.15
up route add -net 192.168.10.0 netmask 255.255.255.0 dev enp2s0
To confirm interface connection speed:
$ ethtool ens160
The command will include the connected speed:
...
Speed: 10000Mb/s
Duplex: Full
...
previous page
|