Network Configuration
Updated: 10/12/2005
General Information
Network configuration in FreeBSD can be a bit difficult because there are a few different text files to edit in order for your changes to be permanent. Hopefully this guide will clear some things up.Requirements
Configuration
I will first show you how to configure your network on-the-fly and then show you how to make the changes persistent.IP Addresses
Before you can set your IP address you need to know which interface to modify. To do this, first runifconfig(8) to see which interfaces you have.|
# ifconfig -a fxp0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 options=8<VLAN_MTU> inet6 fe80::202:b3ff:fe07:9387%fxp0 prefixlen 64 scopeid 0x1 ether 00:02:b3:07:93:87 media: Ethernet autoselect (100baseTX <full-duplex>) status: active plip0: flags=108810<POINTOPOINT,SIMPLEX,MULTICAST> mtu 1500 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 |
| # | ifconfig fxp0 192.168.0.2 netmask 255.255.255.0 |
|
# ifconfig -a fxp0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 options=8<VLAN_MTU> inet 192.168.0.2 netmask 0xffffff00 broadcast 192.168.0.255 inet6 fe80::202:b3ff:fe07:9387%fxp0 prefixlen 64 scopeid 0x1 ether 00:02:b3:07:93:87 media: Ethernet autoselect (100baseTX <full-duplex>) status: active plip0: flags=108810<POINTOPOINT,SIMPLEX,MULTICAST> mtu 1500 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 |
/etc/rc.conf file:| # | echo 'ifconfig_fxp0="inet 192.168.0.254 netmask 255.255.255.0"' >> /etc/rc.conf |
Note: Be sure to change fxp0 to whatever your NIC is.
IP Aliases
If you have one NIC, but want it to listen on multiple IP addresses, you need to add aliases with a 32-bit mask.| # | ifconfig fxp0 alias 192.168.0.100 netmask 255.255.255.255 |
|
fxp0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 options=8<VLAN_MTU> inet 192.168.0.2 netmask 0xffffff00 broadcast 192.168.0.255 inet6 fe80::202:b3ff:fe07:9387%fxp0 prefixlen 64 scopeid 0x1 inet 192.168.0.100 netmask 0xffffffff broadcast 192.168.0.100 ether 00:02:b3:07:93:87 media: Ethernet autoselect (100baseTX <full-duplex>) status: active plip0: flags=108810<POINTOPOINT,SIMPLEX,MULTICAST> mtu 1500 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 |
/etc/rc.conf file:| # | echo 'ifconfig_fxp0_alias0="inet 192.168.0.100 netmask 255.255.255.255"' >> /etc/rc.conf |
Note: Be sure to change fxp0 to whatever your NIC is.
/etc/rc.conf file increment alias0 for each additional alias. For example, if my NIC had two aliases, my /etc/rc.conf would look something like this:|
ifconfig_fxp0_alias0="inet 192.168.0.100 netmask 255.255.255.255" ifconfig_fxp0_alias1="inet 192.168.0.101 netmask 255.255.255.255" |
Default Gateway
In order to route any traffic, a default gateway needs to be set up.| # | route add default 192.168.0.1 |
Note: Change 192.168.0.1 to whatever your default route should be.
To make this route persistent, add it to your/etc/rc.conf
| # | echo 'defaultrouter="192.168.0.1"' >> /etc/rc.conf |
route(8) and then view your routing table with netstat(8).| # | netstat -r |
DNS Servers
You DNS servers get added in/etc/resolv.conf.|
# nano -w /etc/resolv.conf nameserver 68.1.56.33 nameserver 68.1.56.34 |
Additional Notes
Instead of adding all the information to/etc/rc.conf and running the commands to set the changes, you can just add all changes to /etc/rc.conf and then issue the following command to set your network parameters:| # | /etc/netstart |
Author: Jon LaBass
jon at bsdguides dot org