Jan 15, 2004, 6:23 AM
Post #69 of 80
(4418 views)
Permalink
Here is a trace of doing some alias configuration.
2#> ifconfig ex0
ex0: flags=8822<BROADCAST,NOTRAILERS,SIMPLEX,MULTICAST> mtu 1500
capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
enabled=0<>
address: 00:50:da:[redacted]
media: Ethernet autoselect
status: no carrier
3#> ifconfig ex0 10.0.0.1/24
4#> ifconfig ex0
ex0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
enabled=0<>
address: 00:50:da:[redacted]
media: Ethernet autoselect (none)
status: no carrier
inet 10.0.0.1 netmask 0xffffff00 broadcast 10.0.0.255
inet6 fe80::[redacted]%ex0 prefixlen 64 scopeid 0x5
5#> ifconfig ex0 10.0.0.2/24 alias
6#> ifconfig ex0
ex0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
enabled=0<>
address: 00:50:da:[redacted]
media: Ethernet autoselect (none)
status: no carrier
inet 10.0.0.1 netmask 0xffffff00 broadcast 10.0.0.255
inet alias 10.0.0.2 netmask 0xffffff00 broadcast 10.0.0.255
inet6 fe80::[redacted]%ex0 prefixlen 64 scopeid 0x5
now we have 2 addrs
7#> ifconfig ex0 10.0.0.1/24 delete
8#> ifconfig ex0
ex0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
enabled=0<>
address: 00:50:da:[redacted]
media: Ethernet autoselect (none)
status: no carrier
inet 10.0.0.2 netmask 0xffffff00 broadcast 10.0.0.255
inet6 fe80::[redacted]%ex0 prefixlen 64 scopeid 0x5
alias no longer shows up, since .2 is now the first v4 addr.
9#> ifconfig ex0 10.0.0.2/24 alias
10#> ifconfig ex0
ex0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
enabled=0<>
address: 00:50:da:[redacted]
media: Ethernet autoselect (none)
status: no carrier
inet 10.0.0.2 netmask 0xffffff00 broadcast 10.0.0.255
inet6 fe80::[redacted]%ex0 prefixlen 64 scopeid 0x5
I feebed typing; had I typed 1, there would have been a second inet
line with .1 and alias.
11#> ifconfig ex0 10.0.0.3/16
12#> ifconfig ex0
ex0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
enabled=0<>
address: 00:50:da:[redacted]
media: Ethernet autoselect (none)
status: no carrier
inet 10.0.0.3 netmask 0xffff0000 broadcast 10.0.255.255
inet6 fe80::[redacted]%ex0 prefixlen 64 scopeid 0x5
Without alias, the address is replaced.
So, an 'alias' in NetBSD (or *BSD?) is any address past the first
address configured for an interface? If so, then it's a rougher scheme
than Linux, which allows finer chains in the sense that only addresses
implying the very same subnet are primary/secondary related.
Right, except that I'd say simpler rather than rougher; there is
simply no concept of related enforced by the kernel.
In NetBSD (and I think the others) that interfaces simply may have
more than one address (within any given address family). The notion
of alias is IPv4 only, and is purely for interacting with the user in
order to distinguish between the following two requests:
# basic setup for both requests
ifconfig le0 inet 10.0.0.1/24
# request A:
ifconfig le0 inet 10.0.0.2/24
# now le0 has just 10.0.0.2/24 (or any other addr; the netmask of
# the second address is used of course but the replacement happens
# regardless of its value).
# request B:
ifconfig le0 inet 10.0.0.3/24 alias
# now le0 has two addresses. The second one is second because
# addresses are put at the end of the list.
I am pretty sure that in case B the first address will be used for
source selection.
When you do 'ifconfig le0', the second address (and succeeding) are
printed as alias, but that's because ifconfig has logic to get the
first address and prints the word alias on all addresses that aren't
the same. There is no alias flag in the kernel. This means that
alias is printed regardless of whether the subnets match.
I found a local machine with a non-matching subnet on an interface.
After anonymizing, this is what it looks like:
le0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
address: 08:00:20:[redacted]
media: Ethernet autoselect (10baseT)
status: active
inet 10.0.1.1 netmask 0xffffff00 broadcast 10.0.1.255
inet alias 10.0.2.5 netmask 0xfffffff8 broadcast 10.0.2.7
inet6 fe80::[redacted]%le0 prefixlen 64 scopeid 0x1
This is a broken setup; the 10.0.2.0/29 block is for vhosts and there
is no reason to expect to find say .4 on the same ethernet; the point
of the scheme is to distribute all of those addresses to their
servers.
Really this address should be configured as a /32, and I think best
practices call for it to be on lo0 too. (This way only packets that
are routed to the box are answered, and we are very sure that it will
not be used for a source address of a new sendto()/connect().
Note that this is all for IPv4. On IPv6 the default behavior is to
add a new address, not replace. If you want to replace, it is delete
and add (or add and delete). This is because in IPv6 it is normal to
have more than one address, esp. since there is always a link-local
address.
So yes, this lacks the ability of Linux to configure primary and
secondary addresses in arbitrary order, and to then have source
selection use the primary one. It also doesn't auto-delete chained
addresses. In practice, people put the primary address first in
/etc/ifconfig.le0, and then the others, and the lack of this feature
does not cause pain that I have either noticed or heard about.
Also, if you want a 'virtual host' type address that isn't on the
subnet that your main interface is on, typically you put it
Does Linux have the same secondary notion for IPv6?