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
- Local root access on the box or be able to su to root.
- A SSH client that supports ANSI colors such as puTTy or SecureCRT (if you aren't on the box).
- Your favorite text editor (I like nano).
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 run
ifconfig(8)
to see which interfaces you have.# ifconfig -a fxp0: flags=8943 options=8 inet6 fe80::202:b3ff:fe07:9387%fxp0 prefixlen 64 scopeid 0x1 ether 00:02:b3:07:93:87 media: Ethernet autoselect (100baseTX status: active plip0: flags=108810 lo0: flags=8049 inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 |
In this example, I have fxp0 as my main interface. lo0 is the loopback so you don't need to touch it. Now here's how to set the IP to 192.168.0.2 with a subnet mask of 255.255.255.0.
# | ifconfig fxp0 192.168.0.2 netmask 255.255.255.0 |
# ifconfig -a fxp0: flags=8943 options=8 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 status: active plip0: flags=108810 lo0: flags=8049 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
If you have multiple NICs that you want to use, just use the same procedure to add an address to their interface.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 |
Now if you look at your configuration you'll see the additional IP.
fxp0: flags=8943 options=8 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 status: active plip0: flags=108810 lo0: flags=8049 inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 |
You now have an IP address alias set, but if you want it set permanently, add it to your
/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
If your NIC is to have multiple aliases, in your 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 |
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 |
Comments
Post a Comment