Linux, adding sub-interfaces
I'll start out by saying networking isn't my strong suit, I'm trying to configure a few sub-interfaces so that some code I am working will have more sockets to locally bind to. So far i've done the following, I can locally bind to my sub interface 192.168.2.210, but I can not make a remote connection with it.
Here is my ifconfig:
eth0 Link encap:Ethernet HWaddr 00:50:56:BB:00:0B
inet addr:10.6.19.18 Bcast:10.255.255.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:febb:b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1056026 errors:0 dropped:0 overruns:0 frame:0
TX packets:638290 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:237037186 (226.0 MiB) TX bytes:126161362 (120.3 MiB)
eth0:1 Link encap:Ethernet HWaddr 00:50:56:BB:00:0B
inet addr:192.168.2.210 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Here is what i've tried to do to configure eth0:1
ifconfig eth0:1 192.168.2.210/32 up
ip route add 192.168.2.210/32 via 10.6.19.18
Here is my netstat -r output:
192.168.2.210 devserv. 255.255.255.255 UGH 0 0 0 eth0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
10.6.19.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 0 0 0 eth0
default 10.6.19.1 0.0.0.0 UG 0 0 0 eth0
Any thoughts? Thanks for looking
Ditch ifconfig as this is being phased out for the iproute2 package;
root@bensley-n2:~# ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:e0:4c:6d:0a:49 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether 74:ea:3a:ad:2e:00 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.5/24 brd 192.168.0.255 scope global wlan0
inet6 fe80::76ea:3aff:fead:2e00/64 scope link
valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether ce:70:78:f8:10:75 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
root@bensley-n2:~# ip address add 1.1.1.1/24 dev wlan0
root@bensley-n2:~# ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:e0:4c:6d:0a:49 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether 74:ea:3a:ad:2e:00 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.5/24 brd 192.168.0.255 scope global wlan0
inet 1.1.1.1/24 scope global wlan0
inet6 fe80::76ea:3aff:fead:2e00/64 scope link
valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether ce:70:78:f8:10:75 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
root@bensley-n2:~# ip route show
default via 192.168.0.1 dev wlan0
1.1.1.0/24 dev wlan0 proto kernel scope link src 1.1.1.1
192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.5
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
(You can abbreviate the ip
commands: ip address add
can be shortened all the way down to ip a a
, and ip address show
can be shortened to ip a s
. show
is the default action if you don't specify the second argument, so you can just type ip a
if you want to be really terse.)
You don't need to add a route either for a local subnet.
Firstly, sockets aren't actually bound to an interface -- they're bound to an IP address. Virtual/alias interfaces are deprecated and should be avoided -- you should rather add multiple IP addresses directly to eth0
. Secondly, if you want these addresses to be routable on the local network you need to use addresses on that network (i.e. 10.6.19.0/24) and not a machine-local subnet like 192.168.2.0/24 (unless you can get the router or the remote machines reconfigured with this other subnet). To add additional address, use the following command:
ip addr add 10.6.19.19/24 dev bond0
You shouldn't require any additional routing configuration since the addresses are on an existing subnet.