How to Configure Dual IP Addresses on a Single NIC in Ubuntu

Recently I needed to use Linux iptables NAT for port mapping,

but the interface machine only had one NIC and needed both internal and external network access,
so I used the method described below:
1. Assume internal network IP info:
address 192.168.100.6
netmask 255.255.255.0
gateway 192.168.100.1
2. Assume external network IP info:
address 192.168.200.188
netmask 255.255.255.0
gateway 192.168.200.1
3. Assume NIC is: eth0
4. Edit the Ubuntu IP config file:
#vim /etc/network/interfaces
Refer to the content below. Linux users will understand:

1 # This file describes the network interfaces available on your system
2 # and how to activate them. For more information, see interfaces(5).
3  
4 # The loopback network interface
5 auto lo
6 iface lo inet loopback
7  
8 # The primary network interface
9 auto eth0
10 iface eth0 inet static
11 address 192.168.100.6
12 netmask 255.255.255.0
13 #gateway 192.168.100.1
14 # Below is the external IP configuration
15 auto eth0:1
16 iface eth0:1 inet static
17 address 192.168.200.188
18 netmask 255.255.255.0
19 gateway 192.168.200.1

After editing, save with wq! and restart the NIC:

1 #/etc/init.d/networking restart

OK, done.

Leave a Comment

Your email address will not be published.