The following is a common setup where there is a FreeBSD box which is connected to the Internet and various home/office computers need to connect to the Internet via the FreeBSD box.
DHCP server has to be installed separately. No other software installation is necessary (another reason why we like FreeBSD so much as things are always simple and efficient).
Assume 2 network cards:
- Card 1 is re0. It is connected to the Internet. Has a publicly accessible real IP: 116.68.197.38
- Card 2 is rl0. It provides the internal network and is connected to a router/hub where all the office/home PCs are connected. This card / interface has IP: 192.168.1.1
Internet Gateway
Edit /etc/rc.conf. The following lines are required:
gateway_enable="YES"
firewall_enable="YES"
firewall_type="OPEN"
natd_enable="YES"
natd_interface="re0"
natd_flags=""
For clarification, the following lines are also mentioned which you would have setup anyway as part of network configuration:
ifconfig_re0="inet 116.68.197.38 netmask 255.255.255.0"
ifconfig_rl0="inet 192.168.1.1 netmask 255.255.255.0"
defaultrouter="116.68.197.37"
Also make sure you have the following in /boot/loader.conf
ipfw_load="YES"
ipdivert_load="YES"
net.inet.ip.fw.default_to_accept="1"
options IPFIREWALL_DEFAULT_TO_ACCEPT
options IPFIREWALL_VERBOSE
DHCP Server
Install the DHCP Server. For example type the following command:
pkg_add -v -r isc-dhcp30-server
update 2010-09-01: pkg_add -v -r isc-dhcp41-server
Once installed edit /usr/local/etc/dhcpd.conf. As an example, we have the following lines:
option domain-name "beeix.san";
option domain-name-servers 202.53.160.6, 202.53.160.7;
default-lease-time 3600;
max-lease-time 86400;
ddns-update-style ad-hoc;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.200;
option routers 192.168.1.1;
}
That's it - your FreeBSD server has become an Internet Gateway and DHCP server. Now computers connected to your internet network will be able to access the Internet via your FreeBSD box.
|