1

i'm doing some tests for my class, i have a Ubuntu Server 16.04, totally stock.

This server has 3 Ethernet NICs, one of them is connected to my gateway, 192.168.1.1, and the other two are connected to one host each.

Is it possible to have these hosts in separate networks, and still be able to connect to my main gateway, and have internet?

This is my interfaces file:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

allow-hotplug enp2s3
iface enp2s3 inet static
    address 192.168.1.200
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.1
    dns-nameservers 192.168.1.1

allow-hotplug enp2s2
iface enp2s2 inet static
    address 192.168.100.1
    netmask 255.255.255.0
    network 192.168.100.0
    broadcast 192.168.100.255
    gateway 192.168.1.200
    dns-nameservers 192.168.1.200

allow-hotplug enp2s1
iface enp2s1 inet static
    address 192.168.101.1
    netmask 255.255.255.0
    network 192.168.101.0
    broadcast 192.168.101.255
    gateway 192.168.1.200
    dns-nameservers 192.168.1.200
0

Sure is. Gateways should be on the same network as the interface, and in typical setups you should only have one gateway on the interface that goes out to the internet. It's the route of last resort i.e. send everything that's not on my directly connected netowrk/s here. Same with the nameserver it's global for a computer.

So you already have 3 networks set up. Take out gateway 192.168.1.200 and dns-nameservers 192.168.1.200 lines from enp2s1 and enp2s2 /etc/network/interfaces is the configuration for that specific computer. So you're telling your own computer to use it's own ip from another network as a gateway and a dns server. (broadcast and network don't hurt but are not really needed as your PC is much better than you at calculating those).

Now configure PC on 192.168.100.0 255.255.255.0 network with IP and tell the other PC to use your server at 192.168.100.1 as it's gateway, and same with the PC on 192.168.101.0 255.255.255.0 configure it with IP and your server 192.168.101.1 as it's gateway.

Then tell your server to do the routing by uncomenting net.ipv4.ip_forward=1 in your /etc/sysctl.conf

That should be all, but most likely your internet will still not work on your "hosts". Reason being is your router. It only knows of one internal network which is 192.168.1.0/24 and will send EVERYTHING else to it's default gateway which is probably your ISP. e.g. it wouldn't know what to do with packets sent to 192.168.100.X and 192.168.101.0 so it'll forward them back to the internet which your ISP will drop. To fix that you need to log in to your router and add a staic/manual route telling it to forward all packets destined to 192.168.100.0/24 and 192.168.101.0/24 to your server at 192.168.1.200

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.