D. J. Bernstein
Internet publication
djbdns
How to tell a computer to respond to an IP address
Before a computer will talk to the Internet,
you have to configure the computer to respond to at least one IP address.
In particular,
before you can set up a service on a computer,
you have to configure the computer to respond to the service's IP address.
This is separate from
publishing the IP address
of the computer.
Two computers can't respond to the same IP address.
More precisely:
- Public IP addresses, such as 131.193.178.160,
are used to communicate globally,
and are allocated globally.
Only one computer on the Internet can respond to this address.
- Private IP addresses, such as 10.1.2.3,
are used to communicate within a private network
(for example, a company network),
and are allocated by the network operator.
Only one computer within a private network can respond to this address;
however, the same number can be reused in other private networks.
IP addresses
10.0.0.0-10.255.255.255,
172.16.0.0-172.31.255.255,
and
192.168.0.0-192.168.255.255
are private.
- Local IP addresses, such as 127.0.0.1,
are used to communicate within a single machine,
and are allocated by the machine operator.
Every machine has its own 127.0.0.1.
IP addresses
127.0.0.0-127.255.255.255
are local.
A single computer can respond to several IP addresses.
Multiple IP addresses for a single network card
are often called IP aliases.
UNIX systems generally
offer three levels of IP-address configuration mechanisms:
- The ifconfig and route commands,
which tell the computer how to respond until the next reboot.
- Configuration files in /etc
that tell the computer how to respond after a reboot.
- Installation scripts that set up these configuration files.
You had an opportunity to use one of these scripts
to set up an IP address
when you installed the operating system.
The rest of this page shows some system-specific details.
FreeBSD details: first address
A typical use of ifconfig and route is
ifconfig fxp0 1.8.7.200 netmask 255.255.255.0
route add default 1.8.7.1
which means three things:
- The computer should respond to IP address 1.8.7.200.
- To reach other 1.8.7.* IP addresses,
the computer should send packets
through its fxp0 network card.
You can run ifconfig without arguments to see a list of network cards.
- To reach the rest of the Internet,
the computer should send packets
through the router with IP address 1.8.7.1.
To tell the computer to do all this after each boot, add
ifconfig_fxp0="inet 1.8.7.200 netmask 255.255.255.0"
defaultrouter="1.8.7.1"
to /etc/rc.conf.
FreeBSD details: IP aliases
To set up a second IP address, say 1.8.7.246, type
ifconfig fxp0 1.8.7.246 netmask 255.255.255.255 alias
and add
ifconfig_fxp0_alias0="inet 1.8.7.246 netmask 255.255.255.255"
to /etc/rc.conf.
Use alias1 for the third address,
alias2 for the fourth address, etc.
For 127.* addresses, use lo0 instead of fxp0.
Debian GNU/Linux details: first address
A typical use of ifconfig and route is
ifconfig eth0 1.8.7.200 netmask 255.255.255.0
route add default gw 1.8.7.1
which means three things:
- The computer should respond to IP address 1.8.7.200.
- To reach other 1.8.7.* IP addresses,
the computer should send packets
through its eth0 network card.
You can run ifconfig without arguments to see a list of network cards.
- To reach the rest of the Internet,
the computer should send packets
through the router with IP address 1.8.7.1.
To tell the computer to do all this after each boot, add
auto eth0
iface eth0 inet static
address 1.8.7.200
netmask 255.255.255.0
gateway 1.8.7.1
to /etc/network/interfaces.
Debian GNU/Linux details: IP aliases
To set up a second IP address, say 1.8.7.246, type
ifconfig eth0:0 1.8.7.246 netmask 255.255.255.0
and add
auto eth0:0
iface eth0:0 inet static
address 1.8.7.246
netmask 255.255.255.0
to /etc/network/interfaces.
Use :1 for the third address,
:2 for the fourth address, etc.
For 127.* addresses, use lo instead of eth0.
Details for other systems
I realize that this page is incomplete; my apologies.