FreeBSD: HowTo Start / Stop / Restart Network and Routing Service

GIT – is a Unix-like free operating system. You can to choose third party software on FreeBSD from the Ports Collection. Many services such as POP3 server daemons, IMAP, etc. could be started using the inetd.

However, networking can be stop or started using special script located in /etc/rc.d/ directory. This directory includes script to stop or start network, and other services such as SSH server.

FreeBSD 5.x/6.x and above version – start or stop network

FreeBSD 5.x/6.x and above version comes with netif script to start, restart, stop network service. You need to login as a user. Then you can use following commands:

To start FreeBSD network service:
# /etc/rc.d/netif start
To stop FreeBSD network service:
# /etc/rc.d/netif stop
To restart FreeBSD network service:
# /etc/rc.d/netif restart

Manual method using ifconfig

To stop network card (NIC) on-fly:
# ifconfig network-interface down
To start network card (NIC) on fly:
# ifconfig network-interface up
To list down network interface:
# ifconfig -d
To list up network interface:
# ifconfig -u

FreeBSD Update / restart routing tables / service

It is also necessary to update routing table after restating networking service, enter:
# /etc/rc.d/routing restart

How do I restart network service over ssh session?

You need to type the commands as follows in order to avoid any problems:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart

FreeBSD 4.x and prior version only – start, restart, stop network service

1) To start network service under FreeBSD you need to copy special
script as follows:

# cp /usr/share/examples/etc/netstart /etc/network

2) Execute script:

. /etc/network


sh /etc/network

Please note that script will do all necessary work for you i.e. it will start network, routing, firewall etc.

To display the current configuration for the network interfaces on your FreeBSD server, type the following command:
# ifconfig

How Do I Configure the Network Card Under FreeBSD?

You need to use the ifconfig command as follows to assign an IP address:
# ifconfig interfaceName inet IPAddress

To assign an ip to lnc0 interface, enter:
# ifconfig lnc0 inet

Please note that lnc0 is an ethernet interface name. It can be Obtained by tying the following command:
# ifconfig -a

FreeBSD Ntwork Card’s Configuration

To setup up ip address permanently open a file called /etc/rc.conf and append/modify network entries as follows:
# vi /etc/rc.conf
Setup values as follows:
ifconfig_lnc0="inet netmask"
### Default gateway ###

Save and close the file. Please note that ifconfig_lnc0 is Ethernet interface name. It can be Obtained using ifconfig -a command.

You can restart networking service using the following command:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart

FreeBSD IP Alias: Setup 2 or More IP address on One NIC

IP aliasing is the process of assigning more than one IP address to a network interface. This is useful for Apache web server virtual hosting or other network servers such as ftp server.

This tutorial explains how to assign one or more IP address to a single network interface under FreeBSD operating system.

It is possible to create network alias or assign 2 ip address to a single NIC under FreeBSD operating system.

Our Sample Setup

  • Interface name: lnc0 – IP :
  • Interface name: lnc0 alias – IP :

Netmask must be different otherwise you will get an error ifconfig: ioctl (SIOCAIFADDR): File exists.

Set ip alias using ifconfig command line utility

Login as the root user.

Now, use ifconfig command as follows to set alias:
# ifconfig lnc0 netmask alias

Persistent IP Alias Configuration

Edit file /etc/rc.conf to setup persistent ip aliasing option by appending following configuration, so that next time FreeBSD comes up (after restart/shutdown) it will create alias for you:
ifconfig_lnc0_alias0=" netmask"

Finally, Restart FreeBSD network service using network restart script:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart
Display alias and real ip using ifconfig lnc0 command:
# ifconfig lnc0
Sample output:

inet6 fe80::20c:29ff:fe01:ddbd%lnc0 prefixlen 64 scopeid 0x1
inet netmask 0xffffff00 broadcast
inet netmask 0xffff

Sample /etc/rc.conf file with IP aliasing

Here is my /etc/rc.conf file with em0 and em1 interface with 5 aliases:

# default vsnl router interface
# Force 10Mbps for both public and private LAN interace
ifconfig_em0="inet netmask media 10baseT/UTP mediaopt full-duplex"
ifconfig_em1="inet netmask media 10baseT/UTP mediaopt full-duplex"
ifconfig_em0_alias0="inet netmask"
ifconfig_em0_alias1="inet netmask"
ifconfig_em0_alias2="inet netmask"
ifconfig_em0_alias3="inet netmask"
ifconfig_em0_alias4="inet netmask"
# static routing configuration

Further readings:

  • Read ifconfig man page.
Print Friendly, PDF & Email



Bài viết liên quan

Be the first to comment

Để lại lời nhắn