# IP Address Assigning



## kollektiv (Jun 29, 2010)

I'm running a server with FreeBSD and I'm trying to make it use 192.168.1.140 whenever I'm connecting to my router (WRT54GL). When I'm using DHCP, it can assign a new ip when I restart, and then I'd have to change port numbers in port forwarding. In an attempt to fix this, I changed


```
ifconfig_em0="DHCP"
```

to


```
ifconfig_em0="inet 192.168.1.140 netmask 255.255.255.0"
```
j

in /etc/rc.conf.

I setup port forwarding for ssh (on port 21330) to go to 192.168.140 on my router, however I can't login remotely anymore. When I try to ssh in it just hangs without any error output.

Here is what sockstat -4 outputs


```
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS      
root     sshd       5221  3  tcp4   192.168.1.140:21330   192.168.1.108:62433
root     sshd       5177  4  tcp4   *:21337               *:*
root     smbd       2071  20 tcp4   *:445                 *:*
root     smbd       2071  21 tcp4   *:139                 *:*
root     nmbd       2065  6  udp4   *:137                 *:*
root     nmbd       2065  7  udp4   *:138                 *:*
root     nmbd       2065  8  udp4   192.168.1.140:137     *:*
```

The local address doesn't match the foreign address. Also I can't log into mysql remotely either. Any help would be appreciated. Thanks for reading.


----------



## fwaggle (Jun 29, 2010)

Did you put your defaultrouter setting in as well? DHCP might be setting that too.


----------



## kollektiv (Jun 30, 2010)

I setup default routing from these instructions http://www.cyberciti.biz/tips/freebsd-how-to-start-restart-stop-network-service.html and it's still not working.


----------



## fwaggle (Jun 30, 2010)

Unless you linked the wrong page, there's no default router setting in there. If you have this:


```
ifconfig_em0="DHCP"
```

and you want to get rid of DHCP, IIRC the bare minimum you need is this:


```
ifconfig_em0="inet 192.168.0.2 netmask 255.255.255.0"
defaultrouter="192.168.0.1"
```

Because DHCP is most likely configuring your default route for you as well. Simply removing DHCP and then restarting routing as well as networking isn't going to magically tell your machine who it talks to to get outside of your network (I apologize in advance if you meant to link a different article and do actually have a default route configured). 

You'll also likely want to make sure you have a working resolver in /etc/resolv.conf, though that might stay put after you kill DHCP, I'm not sure.

Finally, make sure your static IP is outside of the pool of your DHCP server - you don't want your DHCP server handing out that IP to some other machine and kicking your FreeBSD machine offline.


----------



## wblock@ (Jun 30, 2010)

fwaggle said:
			
		

> Finally, make sure your static IP is outside of the pool of your DHCP server - you don't want your DHCP server handing out that IP to some other machine and kicking your FreeBSD machine offline.



DHCP servers are supposed to ping an address before handing it out, so it shouldn't assign an address if there's already something there.  But that can break in various ways, so using static addresses outside the DHCP range is good practice.


----------



## kollektiv (Jun 30, 2010)

Setting 
	
	



```
defaultrouter="192.168.1.1"
```
 worked. Thanks for your help =).


----------

