Share an internet connection to a local network

Required: One PC with two network cards, one connecting to the outer world and the other to the inner world. Assuming that the eth0 interface goes out and the eth1 interface goes in, the internal network card can be configured by editing the interfaces file:

sudo nano /etc/network/interfaces
auto eth1
iface eth1 inet static
#this will be the gateway adress for the clients connected to this network
gateway 'real_world_ip_address_of_eth0'
dns-nameservers 'some_dns_servers'

Then, the IP forwarding settings must be defined; via command line, using iptables, we have to:

sudo ip addr add dev eth1


sudo iptables -A FORWARD -o eth0 -i eth1 -s -m conntrack --ctstate NEW -j ACCEPT 
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -F POSTROUTING
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

sudo iptables-save | sudo tee /etc/iptables.sav
echo "iptables-restore < /etc/iptables.sav" > /etc/rc.local
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo sed "s/\#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/" -i

Reboot and it’s done.

On the client, the /etc/network/interfaces file should be edited to allow the clients to connect to the otter world via the above configured machine:

iface eth0 inet static
#this is the address of the internal card defined above
 dns-nameservers 'some_dns_servers'

Reboot and it’s done. The server can also be configured to assign IP addresses on connection via DHCP.

Create a network share on Ubuntu using Samba

sudo apt-get update
sudo apt-get install samba

Create a user and a password for samba:

sudo smbpasswd -a <username>

Create a shared directory:

mkdir 'samba_shared_folder'

Backup smb.conf and edit it to include the shared folder:

sudo cp /etc/samba/smb.conf ~

sudo nano /etc/samba/smb.conf ~

Once “smb.conf” has loaded, add this to the very end of the file; there should be nospaces between the lines, and note que also there should be a single space both before and after each of the equal signs.
 path = 'full path to folder'
 valid users = <user_name>
 read only = no

Restart the service:

sudo service smbd restart