This tutorial is to setup a home server with ubuntu 10.04 LTS.

After many hours trawling through different tutorials and manuals (many old and out of date) I thought someone else might be in the same boat as me, so I wrote everything down and thought I’d post here for anyone who might wont it. I hope it helps.

My main aim was to get the internet to pass through the server and to share some media files over the network. Having the internet pass through the server has a few advantages as well as drawbacks. The use of nat and having a good firewall and filtering can give you a bit better security and control but there are some down sides like needing the computer on all the time and a little bit more hardware in another NIC (Network Interface Card). There are many more arguments both for and against so I wont try to sell you ether way this is just how I like it.

The basic things your server will need for this tutorial
  • Freshly installed ubuntu 10.04 LTS 64-bit (I don’t think anything will be different for the 32-bit version but I used 64-bit.)
  • 2x NIC (Ethernet ports)
  • Separate hard drive (2TB) for media files (this isn’t mandatory, you can use any folder one your computer instead.)



Eth0 will be the Internet connection and eth1 will be the connection to the network switch.


Internet connection sharring
We need to set the IP address for the network port (eth1) so open Terminal and type:
Code:
sudo sbin/ifconfig eth1 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255
(enter password when asked, sudo will be used in almost every comand you can skip it by first typing “sudo su” and entering your pass word, this will sign you in as root so you don’t have to put sudo before every command (to sign out of root type “exit”). I don’t mind hiting the 5 extra keys so I leave them in)

eth0 will be left as DHCP dependant (you internet router will give it an IP address)

Then we need to flush the rules in filters and NAT tables.
Code:
sudo iptables --flush
sudo iptables --table nat --flush
And delete all chains that are not in default filter or NAT table.
Code:
sudo iptables --delete chain
sudo iptables --table nat --delete-chain

Now to setup the IP forwarding and masquerading.
(you can find out more about these commands by typeing "man iptables" in terminal.(Press "q" to quit))
Code:
sudo iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
sudo iptables --appent FORWARD --in-interface eth1 -j ACCEPT

Enable packet forwarding by editing sysctl.conf

Code:
sudo nano /etc/sysctl.conf
and un-comment (remove #)
Code:
 net.ipv4.ip_forward=1
(To exit nano press Ctrl + x and select yes to save file then yes again to replace existing file, you will need to do this every time we finish using nano)


That has set it up temporary so to save a copy of the setup just type
Code:
sudo iptables-save | sudo tee /etc/iptables.save
Then we edit rc.local to load at start-up
Code:
sudo nano /etc/rc.local
add the following line at the bottom before “exit 0”
Code:
 iptables-restore < /etc/iptables.save


Setup DHCP server
Install dhcp server
Code:
sudo apt-get install dhcp3-server
Dont panic. It will try to start and fail because we have not set it up yet.

To start we need to set dhcp to work on port eth1
Code:
sudo nano /etc/default/dhcp3-server
Change INTERFACES=”” to
Code:
 INTERFACES=”eth1”


Set routing
Code:
sudo nano /etc/network/interfaces
add the following
Code:
auto eth1
    iface eth1 inet static
       address 92.168.1.10
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255

up route add -host 255.255.255.255 eth1

auto eth0
    iface eth0 inet dhcp
Now to configure DHCP but first a good idea to backup existing config.
Code:
sudo cp /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf_original
With that done we can safely edit dhcpd.conf
Code:
sudo nano /etc/dhcp3/dhcpd.conf
comment out the lines
Code:
default-lease-time 600;

and
Code:
max-lease-time 7200;

now uncomment and change the “# A slightly different configuration” section to something like
Code:
subnet 162168.1.0 netmask 255.255.255.0{
Code:
    range 192.168.1.101 192.168.1.200;
    option domain-name-server 10.0.0.138;
    option routers 192.168.1.10;
    option broadcast-address 192.168.1.255;
    option subnet-mask 255.255.255.0;
    default-lease-time 600;
    max-lease-time 7200;
}
(I can't get that to be one code block)
The domain-name-server should be changed to whatever your DNS is on your internet router/modem

There is allot of different setups you can have, read through the file for some ideas or try “man dhcp3” in the terminal.


Setup samba
First I set the hard drive to mount at start up. This is not a part of samba directly but I find it annoying to mount them every time you restart the computer.
To find the location (eg: /media/MEDIA)
Code:
 mount

To find the UUID (eg: UUID=”749C4D8244CD6E7F”) and file system type.
Code:
sudo blkid

Then edit fstab
Code:
sudo nano /etc/fstab
add the line
Code:
 UUID=749C4D8244CD6E7F /media/MEDIA ntfs defaults 0 0

The default and two 0s at the end are to set the mount opptions to find out more try “man fstab” in the terminal. This should be ok for most people.

Now to the actual setup of samba,
Code:
sudo apt-get install samba
When asked to install packeges without verification select yes.
Backup the smb.conf
Code:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf_original
Now to edit smb.conf
Code:
sudo nano /etc/samba/smb.conf
Find the “; interfaces = 127.0.0.0/8 eth0”
remove the ; and change to read
Code:
interfaces = eth1

and find “; bind interfaces only = yes”
and remove ;
then move to the end of the file and add
Code:
[MEDIA]
Code:
    comment = Music, Movies and TV Shows
    path = /media/MEDIA
    browsable = yes
    gest ok = yes
    read only = no
(again I can't figure out how to stop this moving into to code boxes, [MEDIA] should be at the top with the rest indented with spaces below it.)
This setup will allow anyone who can connect to your network to be able to read and right the share /media/MEDIA. There are many different ways to setup samba there are lots of examples in the smb.conf and even more information by “man smb”



Now restart the computer and your all done!

I you’d like to find out more you you can try as I have mentioned by useing the “man” comand to get the manual for that program, also I found these website helpful:
http://www.linuxhomenetworking.com/
https://help.ubuntu.com/community/Internet/ConnectionSharing
and don’t forget Google and the Ubuntu forums are your friends

Feel free to post a question I’ll try to help with any problems or if something isn’t clear. It may take me a day or more to get back to you but I shall do my best to help you.