I have found myself searching the internet for the correct configuration for Linux subinterfaces. A subinterface is a division of one physical interface into multiple logical interfaces. So why would we do that? I use subinterfaces for hosting multiple SSL sites, DSR returns for localhost for my load balancers, and anything else you would need multiple ips on the same physical interface. In Ubuntu it is easy to add subinterfaces I have never had to add a temporary subinterface in Ubuntu but I guess I figure it is easier to just add it to the system and restart networking. Here is how to add a Ubuntu subinterface with ifconfig.
Adding a Ubuntu subinterface without restarting networking.
1. Add the interface and ip with one step
$ sudo ifconfig eth0:0 192.168.1.253 netmask 255.255.255.0
2. Turn the ip address up
$ sudo ifconfig eth0:0 up
3. Check and make sure it is in ifconfig
$ ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:30:48:28:65:2b
inet addr:192.168.1.5 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::230:48ff:fe28:652b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:101278725 errors:10 dropped:0 overruns:0 frame:10
TX packets:96594294 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3734515707 (3.7 GB) TX bytes:1773845088 (1.7 GB)
eth0:0 Link encap:Ethernet HWaddr 00:30:48:28:65:2b
inet addr:192.168.1.253 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
4. Remember the subinterface is gone unless you add it to /etc/network/interfaces.
Adding a Ubuntu subinterface permanently.
Now that you have added the subinterface without restarting networking, and or rebooting we need to add the ip address to the configuration file on Ubuntu so the new ip address will be on the system when you do some upgrades and need to reboot
1. Open the /etc/network/interfaces file with your favorite editor
$ sudo vi /etc/network/interfaces
2. Add the following lines below your physical interface to create the subinterface on reboot.
auto eth0:0
iface eth0:0 inet static
address 192.168.1.253
netmask 255.255.255.0
3. You can always add more Ubuntu subinterfaces by changing eth0:0 to eth0:1 and eth0:2 and so on.
Here is and example of my complete /etc/network/interfaces file with Ubuntu subinterfaces.
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.5
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
auto eth0:0
iface eth0:0 inet static
address 66.37.141.237
netmask 255.255.255.0
#1 by John on March 9, 2010 - 8:29 pm
Hi,
I’d like to add DHCP Pools and/or IP Ranges per subinterface. Is this something recommended in my case?
1) I want to replace Cisco routing “DHCP Pools” in favor of a true DHCP Server. My problems are, in our environment, we primarily use VLANs and IP ranges within each Vlan for traffic reasons. We have network probes that require the use of an IP range per probe for test purposes.
a. See example below.
b. We have 500 Vlans in our test environment and require Vlans 500-999, each with its own IP range.
Cisco 7206 Config:
ip dhcp pool vlan500
network 10.115.50.0 255.255.255.240
dns-server 10.15.12.9 10.10.1.10
default-router 10.115.50.1
domain-name dvlab.acterna.com
lease 10
!
interface GigabitEthernet5/0.500
encapsulation dot1Q 500
ip address 10.115.50.1 255.255.255.240
ip access-group 100 in
ip nat inside
no cdp enable
Probe Vlan and IP ranges
Vlan GW Start End Mask
500 10.115.50.1 10.115.50.2 10.115.50.14 255.255.255.240
501 10.115.50.17 10.115.50.18 10.115.50.30 255.255.255.240
502 10.115.50.33 10.115.50.34 10.115.50.46 255.255.255.240
.
.
999
Regards,
-John
#2 by Darrell on March 10, 2010 - 6:17 pm
I would start by getting a server setup as a trunk, and then work with your DHCP server settings. Use the link below to help.
http://ubuntuforums.org/showthread.php?t=703387