Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 03-17-2010, 09:41 AM   #1
Registered: Jul 2006
Location: Romania
Distribution: Fedora 12
Posts: 160

Rep: Reputation: 31
dhcp server with two subnets

Hi, I'm trying to build a linux(fedora 12) dhcpd server(and gateway), that have 3 network cards(eth0 have with public ip, eth1 class and eth3 with class).

Because I have just a switch, I want to put both cables(from eth1, eth2) in the switch.
Every client has 2 network card(eth0, eth1).
My question is, is there any way to conf eth0 to take from server ip from class, and eth1 from
The internet will work only on eth0.

my dhcpd.conf for now looks like this:

subnet netmask {
option subnet-mask;
option routers;

subnet netmask {
option subnet-mask;
option routers;

Old 03-17-2010, 01:18 PM   #2
Registered: Jan 2005
Location: Shropshire, England, UK
Distribution: RedHat, Fedora, CentOS..........
Posts: 121

Rep: Reputation: 19
Ok if I am understanding your setup then your asking a lot more than simple DHCP.

The DHCP options you have look good however if you want each client to have an IP on one of each of your internal networks ( and I believe you would either need separate switches or you will need to setup vLANs on the local switch so that you split the local LANs.

As far as your machines on the internal network talking to the internet you will need a few more things enabled before they can talk to the internet.

On the gateway machine you will need to enable IP routing, this can be done by the following command

echo 1 > /proc/sys/net/ipv4/ip_forward
You can also set the above value on most RedHat style distributions in /etc/sysctl.conf by modifying the line

# Controls IP packet forwarding
net.ipv4.ip_forward = 0
and setting it to 1 then running

sysctl -p
This will allow machines with IPs on the different subnets to logically talk to each other.

I am assuming your eth0 has a single IP from your ISP that allows it to talk to the Internet. To allow other machines on the local network to talk through to the net you will need to enable Network Address Translation (NAT) on the gateway machine so it masquerades the IP addresses of the machines on your local network.

A script similar to this will turn on the masquerade options in linux to allow the machines to talk through the gateway to the Internet. I should point out however that this script does not implement any firewall security for the local host and that if your planning on building a gateway you may first want to investigate some of the linux distributions that have the features you need but with firewall and other security measures included.


# Define External and Internal Interfaces.


# Ensure ip_forwarding is enabled.
echo 1 > /proc/sys/net/ipv4/ip_forward

# Clear the IP Tables, NOTE: This will flush ANY firewall rules you have in place already on the machine if you
# need your existing rules you will need to integrate the iptables commands to allow it.
echo Flushing IP Tables
/sbin/iptables -F

# Enable NAT (Masquerade) for the Internal interfaces to the external interfaces.
echo Setting up Masquerade

# Enable NAT
/sbin/iptables -t nat -A POSTROUTING -o $EXT -j MASQUERADE

# Enable the network eth1
/sbin/iptables -A FORWARD -i $EXT -o $INT -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i $INT -o $EXT -j ACCEPT

# Enable the network eth2
/sbin/iptables -A FORWARD -i $EXT -o $INT2 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i $INT2 -o $EXT -j ACCEPT

# Display the IP tables configuration
/sbin/iptables -L

# I have used a program called dnsmasq, this allows the gateway to accept DNS requests for clients on the local network
# and to proxy them to your ISP DNS servers so the internal clients are able to resolve IP's. Your internal clients would
# Need to point to the IP address of the gateway for their network for DNS/nameserver requests.

service dnsmasq restart

Last edited by cardy; 03-17-2010 at 01:20 PM. Reason: Add comment


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
DHCP server having 2 subnets through 2 nics dils Linux - Newbie 2 05-21-2009 05:09 AM
Help with DHCP Failover server with multiple subnets Kolibri Linux - Server 0 05-04-2009 05:50 AM
DHCP Server for several subnets Simon_Sez Linux - Software 5 12-30-2005 06:06 PM
One DHCP server serving 2 subnets scng Linux - Networking 3 07-12-2005 10:57 AM
how can i create subnets on dhcp server castify Linux - Networking 0 07-24-2003 04:13 AM

All times are GMT -5. The time now is 06:13 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration