TCP/IP Setup

Synopsis:

The Internet protocol suite or TCP/IP provides end-to-end data communication specifying how data should be packetized, addressed, transmitted, routed, and received. General computers use Ethernet connections for TCP/IP communications. Ethernet provides the Layer 1 connection, via unshielded twisted pair (UTP) cable and Network Interface Card (NIC) or via 802.11 WiFi. The Layer 2 or Data Link layer is the MAC layer or Ethernet, with Layer 3 IP protocol provided by the OSI stack of the FreeBSD kernel.


I. Determine the NIC's Name
Log into the FreeBSD system as root. Use the ifconfig command to display all interfaces.
#
# ifconfig
#
  # ifconfig
re0: flags=8843 metric 0 mtu 1500
        options=8209b
        ether 78:44:76:c3:3d:8b
        hwaddr 78:44:76:c3:3d:8b
        inet 125.227.251.135 netmask 0xffffff00 broadcast 125.227.251.255
        nd6 options=29
        media: Ethernet autoselect (1000baseT )
        status: active
re1: flags=8843 metric 0 mtu 1500
        options=8209b
        ether 78:44:76:c3:3d:8c
        hwaddr 78:44:76:c3:3d:8c
        inet 172.24.1.254 netmask 0xffffff00 broadcast 172.24.1.255
        nd6 options=29
        media: Ethernet autoselect (1000baseT )
        status: active
lo0: flags=8049 metric 0 mtu 16384
        options=680003
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
        inet 127.0.0.1 netmask 0xff000000
        nd6 options=21
        groups: lo
tun0: flags=8051 metric 0 mtu 1500
        options=80000
        inet6 fe80::7a44:76ff:fec3:3d8b%tun0 prefixlen 64 scopeid 0x4
        inet 10.8.0.1 --> 10.8.0.2 netmask 0xffffff00
        nd6 options=21
        groups: tun
        Opened by PID 664

In the above readout, four interfaces are shown, re0, re1, lo0, and tun0. The NICs in this machine are the re0 and re1. These are Realtek chip based, gigabit Ethernet NICs. The "ether" and "hwaddr" are the Media Access Control or MAC addresses that are factory assigned to these NICs. The Address Resolution Protocol or ARP is used along with Reverse ARP to translate between MAC address and IP address. The interface re0 has a fixed IP address on a public network, provided by an Internet Service Provider or ISP, the media is 1000BaseT (gigabit Ethernet) and the interface is "active". The interface re1 has a fixed IP address on a private network, the internal Local Area Network or LAN, the media is 1000BaseT (gigabit Ethernet) and the interface is "active". The lo0 is the localhost address. It is not tied to any hardware and the standard IPv4 address is 127.0.0.1 with an IPv6 address of ::1. Lastly, the tun0 is a "tunnel" address, which in this case is used by the OpenVPN program and provides a virtual private network (VPN) connection. Note that even without any configuration, the ifconfig command can be used to display this readout and see the "active" interfaces. When a machine has two NICs, connecting an active Ethernet cable can help to identify which card is using what name. Then it helps to place a label on those ports for both the hardware name and the assigned IP addresses.

II. Direct Setting IP Addresses
#
# ifconfig re0 inet 125.227.251.135 netmask 255.255.255.0
# ifconfig re0 up
#

It is possible to also set the netmask by using a slash and the network number

#
# ifconfig re0 inet 125.227.251.135/24
# ifconfig re0 up
#

For dynamic IP addresses, the interface can act as a DHCP client to receive IP, mask, gateway and DNS settings automatically.

#
# ifconfig re0 DHCP
#
III. Placing persistent settings in /etc/rc.conf.
#
# cd /etc
# ee rc.conf
#

ifconfig_re0="inet 125.227.251.135 netmask 255.255.255.0"
ifconfig_re1="inet 172.24.1.254 netmask 255.255.255.0"

There might be a situation where the machine will be attached to a network which has a DHCP Server and allow the configuration to be done prior to deploying on a public network. Here is how to place that into the /etc/rc.conf file.

ifconfig_re0="DHCP"

For more information, see the FreeBSD Handbook.