Skip to content

Configuring NAT for the Linux Virtual Platform

Anton Kolesov edited this page Apr 4, 2016 · 6 revisions

This guide describes how to configure NAT to work with nSIM-based ARC Linux Virtual Platform. It is assumed that your host is an Ubuntu-based system with UFW (Uncomplicated firewall). For other Linux distributions search for the answers in the Internet.

Configure NAT in UFW

This guide is based on https://help.ubuntu.com/14.04/serverguide/firewall.html

First, packet forwarding needs to be enabled in ufw. Two configuration files will need to be adjusted, in /etc/default/ufw change the DEFAULT_FORWARD_POLICY to ACCEPT:

DEFAULT_FORWARD_POLICY="ACCEPT"

Then edit /etc/ufw/sysctl.conf and uncomment:

net/ipv4/ip_forward=1

Similarly, for IPv6 forwarding uncomment:

net/ipv6/conf/default/forwarding=1

Now we will add rules to the /etc/ufw/before.rules file. The default rules only configure the filter table, and to enable masquerading the nat table will need to be configured. Add the following to the top of the file just after the header comments:

# nat Table rules
*nat
:POSTROUTING ACCEPT [0:0]

# Forward traffic from tap0 through eth0.
-A POSTROUTING -s 192.168.218.0/24 -o eth0 -j MASQUERADE

# don't delete the 'COMMIT' line or these nat table rules won't be processed
COMMIT

In the above example replace eth0 with the appropriate interface for your network.

Finally, disable and re-enable ufw to apply the changes:

$ sudo ufw disable && sudo ufw enable

Setting up your ARC Linux

Set default gateway:

[ARCLinux]$ route add default gw 192.168.218.1 eth0

To set default nameserver open /etc/resolv.conf and insert there:

nameserver 8.8.8.8
nameserver 8.8.4.4

Those are DNS server provided by Google (https://developers.google.com/speed/public-dns/docs/using), you can use your own DNS server.

It is recommended that you reload UFW configuration before starting SystemC mode

Configure NFS

It is usually convenient to setup a NFS share between host and target to speed up compile-run-debug cycle.

Install NFS server:

$ sudo apt-get install nfs-kernel-server

Edit /etc/exports: describe you public folder there. For example:

/home/arc/snps/pub *(rw,no_subtree_check,anonuid=1000,anongid=1000,all_squash)

Restart NFS server:

$ sudo service nfs-kernel-server restart

Open required ports in firewall. To make things easier this example will open all ports for the hosts in the tap0 network:

$ sudo ufw allow from 192.168.218.0/24 to 192.168.218.1

Now you can mount your share on the target:

[ARCLinux]$ mount -t nfs -o nolock,rw 192.168.218.1:/home/arc/snps/pub /mnt

Public share will be mounted to the /mnt directory.

Clone this wiki locally