How to set up DHCP and NAT on Vyatta router

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 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:

$ configure

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

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 ( 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, and returned DNS server (, and default gateway (

$ set service dhcp-server shared-network-name PRIVATE subnet start stop
$ set service dhcp-server shared-network-name PRIVATE subnet dns-server
$ set service dhcp-server shared-network-name PRIVATE subnet default-router

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 is connected to eth1, the DHCP service will be running on eth1.

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
$ 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 /config/config.boot file.

$ commit
$ save
$ exit
$ reboot

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by 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 as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean