Building Linux L3 switch/router on x86 - Part9 - DHCP and Samba server Installation and Configuration

This is the last from the series of tutorials that shows building Linux Layer 3 switch on x86 hardware. The tutorial explains DHCP server installation and configuration on CentOS in order to provide IP addresses to the host on LAN. As the switch has enough hard disk space available we will install and configure Samba server to provide Windows users an access to their home directories

DHCP Server Installation and Configuration

1. Install necessary packages

[root@swouter-x86 ~]#  yum install dhcp

2. Configure DHCP server

-Add following lines to /etc/dhcp/dhcpd.conf.

[root@swouter-x86 ~]#  vi /etc/dhcp/dhcpd.conf

#DNS update schemes
ddns-update-style none;

#Ignore clients updates
ignore client-updates;

#Define interface on which is DHCP daemon listenning
DHCPARGS=vlan1;

subnet 172.18.0.0 netmask 255.255.0.0 {
       option routers                  172.18.100.150;                 # gateway on vlan1 internal interface
       option subnet-mask           255.255.0.0;                    # subnet mask
option domain-name              "brezular.dyndns.org";       # domain name given to client
       option domain-name-servers      172.18.100.150;    # the IP of our DNS server
       option time-offset              -18000;                      # Eastern Standard Time - set to what you have
       option ntp-servers        172.18.100.150;                  # the IP of our NTP server
       range                    172.18.0.1 172.18.99.255;         # the first range of IP's our clients will get
       range                   172.18.101.0 172.18.255.254;  # the second range of of IP's our clients will get
       default-lease-time 43200;                                      # how long the client's will keep the same IP
       max-lease-time 86400;

host DNS_server       #reserved IP address
      {
        hardware ethernet 00:23:20:8D:B6:4C;
        fixed-address 172.18.100.150;
      }
host Linux_box         #reserved IP address for host on LAN
      {
        hardware ethernet 00:13:E8:C1:FB:13;
        fixed-address 172.18.100.141;
      }

}

4. Test configuration and start dhcpd daemon

[root@swouter-x86 ~]#  service dhcpd configtest
Syntax: OK

[root@swouter-x86 ~]#  /etc/init.d/dhcpd start
Starting dhcpd: [  OK  ]

5. Make DHCP daemon to be started at the boot time

[root@swouter-x86 ~]#  chkconfig dhcpd on

6. Allow DHCP traffic to reach DHCP server

[root@swouter-x86 ~]# iptables -A INPUT -i vlan1 -p udp --dport 67 -j ACCEPT
[root@swouter-x86 ~]# iptables -A INPUT -i vlan1 -p udp --dport 68 -j ACCEPT

[root@swouter-x86 ~]# iptables -A OUTPUT -o vlan1 -p udp --sport 67 -j ACCEPT
[root@swouter-x86 ~]# iptables -A OUTPUT -o vlan1 -p udp --sport 68 -j ACCEPT

[root@swouter-x86 ~]# /etc/init.d/iptables save

Samba Server Installation and Configuration

In order to allow Windows users on LAN to access their homes directories on CentOS we must install and configure Samba server.

1. Install Samba server

[root@swouter-x86 ~]# yum install samba

2. Create Linux user brezular

[root@swouter-x86 ~]# adduser brezular

User brezular uid=500 belonging to the group gid=500 has been created. The home directory is /home/brezular/

Change the password for user brezular.

root@swouter-x86 ~]# passwd brezular

3. Configure samba server

a) Edit the main configuration file /etc/samba/smb.conf

We can let this file without touch as it is perfectly valid for our needs. If we want to have CentOS visible in a Windows workgroup we must change the workgroup name. As we do not have any printers installed on CentOS, comment the lines starting with [printers]

[root@swouter-x86 ~]#  vi /etc/samba/smb.conf

#Interface on which is Samba running
interfaces = lo, vlan1

#Name of our Windows workgroup
workgroup = Workgroup

#[printers]
#        comment = All Printers
#        path = /var/spool/samba
#        browseable = no
#        guest ok = no
#        writable = no
#        printable = yes

b) Create samba user brezular and set up user's password 

[root@swouter-x86 ~]# smbpasswd -a brezular

c) Start smb daemon and make it started during the boot

[root@swouter-x86 ~]# /etc/init.d/smb start
[root@swouter-x86 ~]# chkconfig smb on

4. Configure firewall to allow host on LAN to access their home directories

[root@swouter-x86 ~]# iptables -A INPUT -i vlan1 -p tcp -m multiport --dport 137,138,139,445 -j ACCEPT
[root@swouter-x86 ~]#iptables -A INPUT -i vlan1 -p udp -m multiport --dport 137,138,139,445 -j ACCEPT

[root@swouter-x86 ~]#iptables -A OUTPUT -o vlan1 -p tcp -m multiport --sport 137,138,139,445 -j ACCEPT
[root@swouter-x86 ~]#iptables -A OUTPUT -o vlan1 -p udp -m multiport --sport 137,138,139,445 -j ACCEPT

[root@swouter-x86 ~]# /etc/init.d/iptables save

5. Set SElinux policy to allow samba users to access their home directories

[root@swouter-x86 ~]# setsebool -P samba_enable_home_dirs=1

END.

The following articles had been intensively used during writing of this tutorial.

DHCP server
http://www.linuxhelp.net/forums/Setup_Simple_Dhcp_Server_t4052.html
http://www.howtoforge.com/home-gateway-firewall-with-dhcp-server-for-connection-sharing-centos5
http://www.linuxjunkies.org/articles/dhcp-dejunkified.html

Samba server
http://crazytoon.com/2007/05/22/samba-how-do-you-install-and-set-up-samba-in-linux-redhat-enterpriserhel-centos-fedora/
http://www.centos.org/docs/4/html/rhel-sag-en-4/s1-samba-configuring.html
http://troy.jdmz.net/samba/fw/
http://forums.fedoraforum.org/showthread.php?t=61018
http://www.redhatlinux.info/2011/11/configure-samba-server.html

4 thoughts on “Building Linux L3 switch/router on x86 - Part9 - DHCP and Samba server Installation and Configuration

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.