Last updated on October 10, 2012 by Dan Nanni
Vyatta (now renamed to VyOS) is a feature-rich enterprise class software router. You can download a free community version of Vyatta. Vyatta router can easily be built on a physical machine via a well-packaged LiveCD, or on a VMware virtual machine (VM) via a custom virtual appliance. As a ready-made software router, Vyatta can be configured extremely easily to run as a NAT gateway with DHCP, DNS and NAT functionality.
The following guide shows you how to set up DHCP and NAT on Vyatta router by using Vyatta's command line interface (CLI).
I assume that you already installed Vyatta on your machine or VM. I also assume that the router has two interfaces:
eth0 (WAN interface) and
eth1 (LAN interface connected to
192.168.1.0/24). Now proceed as follows.
Log in to the Vyatta router, and type the following commands.
$ install image $ reboot
Now, enter the Vyatta's CLI by running:
At this point, you are in the Vyatta configuration mode, and are ready to use Vyatta's CLI commands. Run the rest in configuration mode.
$ set system host-name [router-host-name] $ set system domain-name [router-domain-name] $ set interfaces ethernet eth0 address dhcp $ set interfaces ethernet eth1 address 192.168.1.1/24
In the above, you set the name of the router, and configure router's two interfaces. The WAN interface (
eth0) uses DHCP to get its IP address assigned dynamically, while the LAN interface (
eth1) gets its IP address (
192.168.1.1) statically assigned.
In the next set of commands, you will then configure the DHCP service of the router for internal networks: DHCP address range (from
to 192.168.1.100), and returned DNS server (
22.214.171.124), and default gateway (
$ set service dhcp-server shared-network-name PRIVATE subnet 192.168.1.0/24 start 192.168.1.50 stop 192.168.1.100 $ set service dhcp-server shared-network-name PRIVATE subnet 192.168.1.0/24 dns-server 126.96.36.199 $ set service dhcp-server shared-network-name PRIVATE subnet 192.168.1.0/24 default-router 192.168.1.1
Note that you don't have to specify which interface the DHCP service is associated with. The interface to use for DHCP service is automatically determined by the subnet associated with DHCP service. In this example, since the DHCP's subnet
192.168.1.0/24 is connected to
eth1, the DHCP service will be running on
Once DHCP has been configured, you will then go ahead and set up NAT on the router.
$ set nat source rule 10 outbound-interface eth0 $ set nat source rule 10 source address 192.168.1.0/24 $ set nat source rule 10 translation address masquerade
Finally, you must commit your configuration, and save it permanently before exiting. The saved configuration will be stored in
$ commit $ save $ exit $ reboot
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.