Creating IP Aliases


There's nothing to stop you from assigning as many IP addresses as you want to an Ethernet card. Recalling the discussion of ARP from the previous chapter, a new TCP/IP connection looks up a LAN host by its IP address, asking for the MAC address of whatever Ethernet interface has that IP address. It doesn't do the reverse. One MAC address can answer for many different IP addresses, but one IP address can't be assigned to multiple Ethernet cards without errors and collisions resulting.

The way to assign multiple IP addresses to a single card is through IP aliasing. As with the route command, every platform does aliasing slightly differently, and the syntax varies from system to system. On FreeBSD, alias is used as a keyword to ifconfig, appended after the address and all other parameters:

# ifconfig fxp1 64.41.131.103 netmask 255.255.255.255 alias


Note that the netmask is set to 255.255.255.255. This is required if the alias IP address is on the same subnet as the primary IP address for that interface. (If it's not, just use the regular netmask you would use for that subnet.) What does this mean from a TCP/IP standpoint? A netmask where all the bits are set to 1 ensures that the TCP/IP stack will only treat a packet where the destination address matches in all its bits as though it's on the local subnet; the netmask is creating a "subnet" of just that one address, as you can see by doing the binary math to match the address with the netmask:

  0100 0000 0010 1001 1000 0011 0110 0111 (64.41.131.103) + 1111 1111 1111 1111 1111 1111 1111 1111 (255.255.255.255)   0100 0000 0010 1001 1000 0011 0110 0111 (64.41.131.103)


Thus only packets explicitly addressed to that address are accepted. All packets to and from that address are sent to the router and not to the LAN. If multiple aliases had the same netmask, their broadcast addresses would be the same, which would confuse the TCP/IP stack. Using an all-1's netmask is how you trick ifconfig into allowing multiple IP addresses on a single interface.

To set up IP aliases in your /etc/rc.conf, you would use the ifconfig_xxx#_alias# keyword, which works syntactically just like ifconfig_xxx#. Here's how a set of aliases in /etc/rc.conf might look:

ifconfig_fxp1="inet 64.41.131.131 netmask 255.255.255.0" ifconfig_fxp1_alias0="inet 64.41.131.132 netmask 255.255.255.255" ifconfig_fxp1_alias1="inet 64.41.131.133 netmask 255.255.255.255" ifconfig_fxp1_alias2="inet 64.41.131.134 netmask 255.255.255.255" ifconfig_fxp1_alias3="inet 64.41.132.161 netmask 255.255.255.0" ifconfig_fxp1_alias4="inet 64.41.132.165 netmask 255.255.255.255" ifconfig_fxp1_alias5="inet 64.41.132.166 netmask 255.255.255.255"





FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net