Before you upload an internet site, you better test it on your local machine. To do that, you should allocate an IP address known as a loopback address that does not require a modem for access. If you’ve installed Apache Httpd server, you’ll probably get an HTML page that reads “It works” upon connecting to “http://localhost” or http://127.0.0.1” from the web browser. But what if you want to create another site? How to make your server recognize an IP?
In this post I will describe by example the process of adding a local IP.
Step 1: Associate an IP with a Domain Name
If you want to create a domain name such as ‘example.coq‘, add a line for it in /etc/hosts in the format:
Step 2: Attach the IP Address To a Network Interface
To make an address available to internet servers, attach it to a network interface.
A network interface is the identifier followed by colons at the beginning of blocks returned by the command
In this block
lo0 is an interface name.
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384 options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6> inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2 inet 127.0.0.1 netmask 0xff000000
From the prefix ‘lo’ of the interface name, you can know it is a loopback interface.
You can attach an address, login as root, and run ifconfig like in the following example:
ifconfig lo0 127.0.0.2 netmask 255.255.255.255 alias
This will attach IP address 127.0.0.2 to the loopback interface ‘lo0’
You can make the operating system add it each type you start your computer, by adding the following line to
ifconfig_lo0_alias0="inet 127.0.0.2 netmask 255.255.255.255"
You can learn more about virtual hosts from the section ‘11.6 Virtual Hosts” of the FreeBSD Handbook
Step 3: Start a Listening Server
Now, you can start a server that will listen on your address. You can do it by adding a virtual host in apache httpd, create a server in ‘node.js’, etc.
If you’ve installed ‘Apache24’ from the ports, you can find documentation in
'/usr/local/share/doc/apache24'. In addition, you can find documentation in the httpd site.
Written with StackEdit.