Simple Network Segement Setup

Setup


Add additional IP on existing Linux box assuming you already have eth0 NIC defined on Linux

sudo ip address add 192.168.1.125/24 dev eth0

This will add new IP address '192.168.1.125' on eth0 device. So we are listening to a new IP address on eth0 also we can add multiple other IPs to eth0 at this point.


You can see all your additional IPs on eth0 using the following command.

ip a | grep eth0


Let's assume the Linux box already had a default IP address that was accessible from the network '192.168.88.250'.

We need to define routes for new IP addresses we defined in Linux box in the other servers.

Let's assume we have a windows system that we want to communicate on the Linux server using '192.168.1.125'

On the window server we need to run the route command and define a new route as follows;

route add 192.168.1.0 MASK 255.255.255.0 192.168.86.250

This route will redirect traffic for 192.168.1.0 segment to 192.168.86.250 gateway which is our Linux server.


Test the connection

On the Linux box lets listen to TCP commination using Netcat (nc) command.

nc -l 192.168.1.125 3000

On the window system we can use telnet or nc command to connect the linux nc listening server.

nc 192.168.1.125 3000

There you have it!

Useful Commands to manage Linux Networks

Network Namespaces allows admins to segregate different network on the same computer. The network namespaces are isolated networks that can't directly communicate with the host system or each other!


List all network namespaces

sudo ip netns

Add new namespace

sudo ip netns add network-1

sudo ip netns add network-2

Add virtual ethernet in the namespace

This command creates pair of NIC veth0@veth1 and veth1@veth0

sudo ip -n network-1 link add type veth

List all NICs on the network namespace

sudo ip -n network-1 link

Bringing veth0 NIC up on network namespace

sudo ip -n network-1 link set veth0 up

Assigning IP to NIC in the network namespace

sudo ip -n network-1 a add 192.168.1.125/24 dev veth0