# dhcp server configuration issue



## kalns (Feb 17, 2009)

Hello every one!

First of all... I`m new to FreeBSD and have allmost no expirience with unix systems, all the time i was, and at moment i`m using windows  

what i`m doing and whats my problem ?

i`m trying to settup web/mail/dhcp and some other services on my secondary machine 

my problem is with DHCP server, it is installed, and configured (i followed some few tutorials, and one friend of my helped but i dont know why i cant share internet with that machine..

here is my local network displacement on my house at moment

[DSL modem]-->[D-link DL-624]-->[My PC]

what i want to do is 

[DSL modem]-->[D-link DL-624]-->[FreeBSD server]-->[My PC]

machine who has freebsd installed has 2 lan cards, rl0 and rl1 (realtek)

when i connect all pc's like i would like i dont get any internet, only lan connection is available.. 

here is my configurations

rc.conf

```
mc_enable="YES"
gateway_enable="YES"
hostname="SCTG"
keymap="us.iso"
linux_enable="YES"
sshd_enable="YES"
dhcpd_enable="YES"
ifconfig_rl0="DHCP"
### web server ###
mysql_enable="YES"
lighttpd_enable="YES"

### Router ###
dhcpd_ifaces="rl1"
defaultrouter="192.168.0.1"
ipnat_enabl="YES"
ifconfig_rl0="inet 192.168.0.107 netmask 255.255.255.0"
ifconfig_rl1="inet 192.168.0.1 netmask 255.255.255.0"
named_enabl="YES"

ppp_enable="YES"
ppp_nat="NO"
ppp_mode="ddial"
```


dhcpd.conf

```
option domain-name "apollo.lv";
option domain-name-servers 195.122.1.242;
option subnet-mask 255.255.255.0;

default-lease-time 86400;
max-lease-time 86400;
ddns-update-style none;

subnet 192.168.0.0 netmask 255.255.255.0 {
 range 192.168.0.100 192.168.0.254;
option routers 192.168.0.1;
}
```

freebsd machine works fine when its just connected to router, it gets internet, and lighttpd webserver works fine, allso ssh is working fine..

now i`m starting to wonder, if its even posible to connect everything like i want, maybe i should connect everything like this ?

[DSL modem]-->[FreeBSD server]-->[D-link DL-624]-->[My PC]


Feel free to add any comentary, good or bad its no matter, in my country every nobudy is polite when newbie asks any questions, so i`m "immune" to comentary like "what are you doing get out of here!!!" etc 

i would be gratefull if some one could help me to fix this problem.

Btw i`m using FreeBSD 7.0
machine specs are 
P3 933Mhz processor
512 SDRAM
20Gb IDE HDD

network specs
10mbit/s
i know its slow but its best i can get here for affordable price >.<

ps on this lan configuration 
[modem]->[dlink]-pc's 
are connected 3 pc's, 2 are desktop pc's and 1 laptop via wireless

Thanks for reading this huge post, and sorry for my bad language


----------



## kalns (Feb 17, 2009)

couldnt find "edit" button so i`m writing here..

is posible that i cannot access network because my DNS server ip is wrong ? just got primary and secondary ip's from some firiend who works for my isp


----------



## kalns (Feb 17, 2009)

just spoted something.. server is providing me correct ip gateway etc.. but i cannot ping over lan and this part confuses me 

should pc with xp configured to custom ip, or leave it to obtain ip automatically?


----------



## DutchDaemon (Feb 17, 2009)

```
ifconfig_rl0="inet 192.168.0.107 netmask 255.255.255.0"
ifconfig_rl1="inet 192.168.0.1 netmask 255.255.255.0"
```

Pretty sure that's a no-no right there. These are overlapping networks on both interfaces, which will confuse the hell out of your network stack and all services running on that machine. It can find the gateway (because it's directly connected), but making the gateway available to connections coming in from the LAN will not work. Better use a different network on the LAN (like 10.0.0.0/24 or 192.168.1.0/24), use NAT, and be careful about which service to bind to which interface. E.g.: you want DHCP on your LAN side, not on the Internet side. This has nothing to with Windows/Unix, it's basic networking.


----------



## kalns (Feb 17, 2009)

so instead of 

```
ifconfig_rl0="inet 192.168.0.107 netmask 255.255.255.0"
ifconfig_rl1="inet 192.168.0.1 netmask 255.255.255.0"
```
i should put there

```
ifconfig_rl0="inet 192.168.0.107 netmask 255.255.255.0"
ifconfig_rl1="inet 192.168.0.106/24 netmask 255.255.255.0"
```
106 is ip for my pc from router
as far i know my router blocks all ports that i have not farwoded, and i could just open all ports on freebsd machine, for easier usage, so i wont have to open every port i want to use..

is posible to link my desired lan as i showed befour ?
[DSL modem]-->[D-link DL-624]-->[FreeBSD server]-->[My PC]


----------



## DutchDaemon (Feb 17, 2009)

Both IP addresses are in the same network (192.168.0.0-192.168.0.255). By the way, "/24" = 255.255.255.0. Can't use them both. Anyway, your networks must be separate, non-overlapping. 

Your LAN setup in itself is entirely plausible. I guess millions of people have a network like that, including myself. With non-overlapping networks, and NAT. Or with a bridge. But let's not get ahead of ourselves. 

I'd advise you to read up on network basics (these _are_ basics) and follow the FreeBSD handbook to get your network up and running. Wait with DHCP until you've accomplished that.


----------



## kalns (Feb 17, 2009)

heh and i think i new something about basic networking, seems like they have nothing worth teached me  

if i use 10.0.0.0/24  instead of 192.168.x.x/24 could this solve my problem ?

and i write like so would it be correct ?
ifconfig_rl1="inet 192.168.0.106/24"
if i understud you right then /24 is thesame as netmask, am i correct ?


----------



## ctaranotte (Feb 17, 2009)

Ok;

1) As in rc.conf: 



> ifconfig_rl0="DHCP"



you need to take out the line: 



> ifconfig_rl0="inet 192.168.0.107 netmask 255.255.255.0"




2) Why do you need the lines?



> ppp_enable="YES"
> ppp_nat="NO"
> ppp_mode="ddial"



as the FreeBSD server gets its IP from the DHCP server on the D-link DL-624.


3) Your DNS need some reordering. On the D-link DL-624, you need to point any name resolution to the DNS of your provider.

On your FreeBSD server, if you really need BIND (which I doubt), then correct the line: 



> named_enable="YES"



otherwise, the DHCP server on the D-link DL-624 would give your FreeBSD server you provider DNS which would be stored in /etc/resolv.conf.


4) Your config should be either:

[DSL modem]
     |
FreeBSD server]
     |
switch-->[D-link DL-624]
     |
[My PC]

or 

[DSL modem]
     |
[D-link DL-624]-->FreeBSD server]
     |
[My PC]

In the first config, the FreeBSD server will distribute IPs to your PC and to the D-link DL-624 which in turn will distribute IPs to its clients.

In the second config, the D-link DL-624 will distribute IPs to your PC and the FreeBSD server.


----------



## DutchDaemon (Feb 17, 2009)

I actually have

[DSL]--[FreeBSD server/NAT/DHCP]--[switch]--[laptops]

The server does DHCP on the inside, and has the DSL's public IP on the outside, the laptops NAT to that address. Plenty of variations possible on this theme.


----------



## kalns (Feb 17, 2009)

second config is how its connected at moment to internet, reason why it wont be great to leave it so, is because that server is noisy, and router is practicly in parents room, if the router would be in cockloft it wont be a problem..

thanks for advices and corrections, its late now (12:50AM by my time) and its time to go to bed  new day will come with fresh start on reading


----------



## kalns (Feb 18, 2009)

btw if 
ifconfig_rl0="inet 192.168.0.107 netmask 255.255.255.0"
is not defined in rc.conf then no internet access is available on server
second defined outgoing network to my pc


----------



## Mel_Flynn (Feb 18, 2009)

DutchDaemon said:
			
		

> I actually have
> 
> [DSL]--[FreeBSD server/NAT/DHCP]--[switch]--[laptops]
> 
> The server does DHCP on the inside, and has the DSL's public IP on the outside, the laptops NAT to that address. Plenty of variations possible on this theme.



Adding a me-too, but more:

```
/- cable lan
[DSL]--[FreeBSD proxy/nat/dhcp/wireless hostap]
                                               \- wireless
```


----------



## ctaranotte (Feb 18, 2009)

kalns said:
			
		

> btw if
> ifconfig_rl0="inet 192.168.0.107 netmask 255.255.255.0"
> is not defined in rc.conf then no internet access is available on server
> second defined outgoing network to my pc



In that case, enable and/or check your DHCP config on the D-link DL-624 as the ifconfig_rl0 flag is set to "DHCP". You should be able to assign a fixed IP to your rl0 by using its MAC. 

In addition, you may (but don't need to) locally assign an IP to rl0 on your FreeBSD server by removing from your rc.conf:



> ifconfig_rl0="inet 192.168.0.107 netmask 255.255.255.0"



and adding:



> ifconfig_rl0_alias0="inet 192.168.XXX.XXX netmask 255.255.255.0"



Of course 192.168.XXX.XXX <> 192.168.0.107


----------



## kalns (Feb 18, 2009)

and what will the alias do ? i`m sorry but i didnt fully understud you


----------



## Mel_Flynn (Feb 18, 2009)

kalns said:
			
		

> and what will the alias do ? i`m sorry but i didnt fully understud you



Alias will create additional IP's on a given interface. Example from my gate:

```
ifconfig_rl0="inet 192.168.2.10 netmask 255.255.255.0" # Main interface for host access
ifconfig_rl0_alias0="inet 192.168.2.1 netmask 255.255.255.0" # Default route for network
ifconfig_rl0_alias1="inet 192.168.2.11 netmask 255.255.255.0" # Mailhub relaying to inside
ifconfig_rl0_alias2="inet 192.168.2.12 netmask 255.255.255.0" # Squid proxy
ifconfig_rl0_alias3="inet 192.168.2.51 netmask 255.255.255.0" # named
```

As you can see these are all within the same network.


----------



## DutchDaemon (Feb 18, 2009)

Use a 255.255.255.255 netmask for aliases in the same network on FreeBSD!


----------



## Mel_Flynn (Feb 18, 2009)

DutchDaemon said:
			
		

> Use a 255.255.255.255 netmask for aliases in the same network on FreeBSD!



That used to be true, but the network stack doesn't need that anymore. I even have mixed the netmask for aliases on one host with several jails and so far (6+months) have been unable to find any differences with the behavior. As far as I'm concerned the netmask part for aliases is cosmetic.


----------



## DutchDaemon (Feb 18, 2009)

As long as the handbook and ifconfig(8) don't tell me to use anything else, I won't advise anyone else to do so.


----------



## kalns (Feb 18, 2009)

so if i`ll add folowing line then everything should be ok with my networking ?

```
ifconfig_rl0_alias0="inet 192.168.0.1 netmask 255.255.255.0" #default gateway in my case
```

i`m starting to think that my router is allso using this ip including admin panel, they will conflict or not ?


----------



## Mel_Flynn (Feb 18, 2009)

It may be more an issue if you have different networks on the same network card, as illustrated in the handbook.

Before, you couldn't even reach the IP address from outside the host if you didn't have the 0xffffffff netmask. Now it simply works. It may still be proper to use the all ones.

The only difference is seen in the routing tables:

```
192.168.2.0/24     link#3             UC          0        0    em0
[color="DarkGreen"]192.168.2.70       00:07:e9:a0:17:99  UHLW        1   371353    lo0[/color]
[color="Blue"]192.168.2.100      00:07:e9:a0:17:99  UHLW        1  2010838    lo0[/color]

[color="DarkRed"]192.168.2.108/32   link#3             UC          0        0    em0[/color]
```
Main IP
Alias with netmask identical to network
Alias with all-ones netmask


----------



## DutchDaemon (Feb 18, 2009)

Yep, I witnessed that 'binding to localhost' several times, which is why I stuck with the 255 netmask. There may be no real difference when it reaches the lower layers, but I stick with the docs for now. Also because there are people on FreeBSD < 7 around where it still might cause socket errors.


----------



## kalns (Feb 19, 2009)

For Your Information: i think you have misunderstud me

rl0 is for incoming network for server
rl1 is for outgoing to my pc

today i had consultation with one of my teachers (well knows about linux) and he told me that i should bind rl1 as dhcp not rl0

```
ifconfig_rl[color="Red"]1[/color]="DHCP"
```

or i`m getting everything wrong ?


----------



## DutchDaemon (Feb 19, 2009)

I guess you really need to post a more detailed network drawing with network interfaces included. Something like:

[D-Link] ---- [(rl0) FreeBSD (rl1)] --- PC

Anyway, the network connected to the DHCP server should have "DHCP" in its config, of course.


----------



## ctaranotte (Feb 19, 2009)

kalns said:
			
		

> For Your Information: i think you have misunderstud me



No sir, you did not make your point loud and clear.



			
				kalns said:
			
		

> rl0 is for incoming network for server
> rl1 is for outgoing to my pc
> 
> today i had consultation with one of my teachers (well knows about linux) and he told me that i should bind rl1 as dhcp not rl0



No, it would be safer to leave in rc.conf the following as your DNS is on that IP:



> ifconfig_rl1="inet 192.168.0.1 netmask 255.255.255.0"



In summary, in your first config:

* rl0 should assigned an IP by the D-link DL-624 along with the primary and secondary DNS.

* rl1 is assigned 192.168.0.1

* Your PC would be assigned an IP by your D-link DL-624.


Allow me now to anticipate your next questions:

1) "What would be the primary and secondary DNS assigned to my PC?"; The safest and hasslefree answer would be to declare the primary and secondary DNS of your provider in dhcpd.conf.

2)"What if I really want a DNS server on my FreeBSD box?. Try /usr/ports/dns/djbdns instead.

2) "What if I connect my PC to the D-link DL-624 directly so as to let my parents sleep at night? (These are your words)". Yes, in that case check the DHCP server config on the D-link DL-624.

3) "What if I really want the DHCP server on the FreeBSD box to assign IPs to all my internal network?". It all depends on whether or not your D-link DL-624 could be assigned an IP by another DHCP server in an internal network.

4) "How would I know or do that?". Read the fine manual of your D-link DL-624.


A last point, it is a learning curve and we all have gone there and done that .


----------



## kalns (Feb 19, 2009)

i`m sorry if i wasnt clean enough with what i want to do..

leats simplify everything..

i want that my network displacement whould be like this

[incoming DLS internet connection]--->[DL-624 router]-->[rl0 freeBSD rl1]-->[my pc]

rl0 for incoming internet as it is at moment and rl1 for outgoing internet connection

why i asked about dhcp is because some local people who helped out with setup told me that i need it..


----------

