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

subnet netmask {
       option routers        ;                 # gateway on vlan1 internal interface
       option subnet-mask ;                    # subnet mask
option domain-name              "";       # domain name given to client
       option domain-name-servers;    # the IP of our DNS server
       option time-offset              -18000;                      # Eastern Standard Time - set to what you have
       option ntp-servers;                  # the IP of our NTP server
       range          ;         # the first range of IP's our clients will get
       range         ;  # 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;
host Linux_box         #reserved IP address for host on LAN
        hardware ethernet 00:13:E8:C1:FB:13;


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

#        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


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

DHCP server

Samba server

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

Leave a comment

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