Build a Router on CentOS 7

By | September 22, 2016

Like most people, I’m accessing the internet using a cable modem and wireless router, which provides me with a single IP subnet. Unlike most people, I test OpenStack in my basement. To be able to run OpenStack, I’ll need at least one more subnet to work with. Therefore, I need a router.

We can easily build a router out of a physical or virtual Linux machine with two network interfaces. Essentially, we install the operating system (CentOS 7 in this example), configure the network (IP addresses and such), and then configure the firewall.

Below is a diagram of what we’re trying to create. The CentOS 7 machine will have its first NIC attached to the “External” facing network, which is the subnet that the wireless router provides me. The second NIC will be attached to an “Internal” network that I can use as a network for my OpenStack instances.


We’ll use the following configuration to setup the router:

       Hostname: router
NIC1 IP Address:
   NIC1 Netmask:
   NIC1 Gateway:

      NIC1 DNS1:
      NIC1 DNS2:

NIC2 IP Address:
      NIC2 CIDR:

Getting the Script

Once you’ve built your CentOS 7 machine with it’s two NICs, you can download and execute the script. Run these commands from the CentOS 7 machine:

curl -O
tr -d '\r' < pnqkPNdK >
chmod +x

Now you can execute the script using our configuration information:

sudo ./ -n router -i \
  -m -g \
  -d -d2 \
  -i2 -c

The script will configure both NICs and execute the firewall commands. When finished, the network and firewall services will be restarted, which may disconnect your ssh session. You can reconnect using the new NIC1 IP address. Note: sometimes the network restart doesn’t use the new IP addresses right away. If you remain connected to the old IP address after running the script, you can try restarting the network again using this command:

systemctl restart network.service

Adding a Route to Your Wireless Router

There’s one more step we need to cover. All of the devices on your “External” network are using your Wireless router as the default gateway. So, in order for these devices (including your laptop) to reach devices on our new “Internal” network, we need to tell our wireless router to forward any┬ápackets destined for the network to our new router. To do this, we need to logon to the wireless router and add a route. This is typically in the advanced configuration settings of the wireless router.

For example, in the Verizon FIOS router, logon and select Advanced – Routing – New Route and fill out the form as shown below:


That should do the trick. You now have a functioning router and a new subnet.

Source Code

Leave a Reply

Your email address will not be published. Required fields are marked *