# Setting up static IP address



## freebird1 (Apr 17, 2014)

I might be overlooking something. As a test to make sure I could even connect to the internet from FreeBSD 10 (set up in Virtual Box) I pinged 4.2.2.2 after setting it to DHCP. Now I want it to be static. I am basically virtualizing a network. FreeBSD I want to act as a router to the rest of my hosts. Routers or servers aren't set to fuck in real life so I don't want mine to be that way.

I am able to set the static IP up by going to rc.conf  like this.

```
Ifconfig_em0="inet 192.168.1.105 netmask 255.255.255.0"
defaultrouter="192.168.1.1"
```
When I reboot and do an `ifconfig em0`, there is no up address there.  Not even a field for inet.  

What am I missing?
Thanks


----------



## asteriskRoss (Apr 17, 2014)

In your post you had a capital rather than a lower case "i" in "Ifconfig_em0" from the first line of your configuration, though it's possible this might be a typographical error in your post rather than in rc.conf. The first line should be:

```
ifconfig_em0="inet 192.168.1.105 netmask 255.255.255.0"
```

If that isn't the issue, what messages are there relating to em0 in /var/log/messages?  Can you successfully set the address manually with the command `ifconfig em0 inet 192.168.1.105 netmask 255.255.255.0` ?


----------



## freebird1 (Apr 18, 2014)

Hi and thank you.

Yes, that was a typo as I was on my phone yesterday writing.  There is no caps in the rc.conf.
I was able to manually set the IP address as you suggested.  I verified this after setting it by doing an ifconfig em0.  But when I ping I get no route to host when I try to ping 4.2.2.2 (but no router is set up as it is not reading from what I wrote in rc.conf).  But I am able to ping my router though 192.168.1.1.


----------



## asteriskRoss (Apr 18, 2014)

Your test proves the network interface is working fine, so we should look at why it isn't being configured on boot.  Can you post all of your /etc/rc.conf?  Have you double checked that you're booting to the system you configured (I recall that Virtual Box boots to its virtual CD drive by default if an image is attached)?


----------



## freebird1 (Apr 18, 2014)

Yes one of the first things I did when I installed FreeBSD was I had to remove the iso from the virtual cd in VirtualBox since it kept trying to mount from there.  
I set VB to a bridged connection as well.  Tried NAT, but that does not allow me to even ping my router.  It will say gateway is down.  

Contents of rc.conf are as follows.


```
hostname="routerfreebsd"
sshd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"
ifconfig_em0="inet 192.168.1.104 netmask 255.255.255.0"
defaultrouter="192.168.1.1"
```


----------



## freebird1 (Apr 18, 2014)

Actually I just was able to ping 4.2.2.2 
I originally had defaultrouter in the inet portion.  I tested it using the above code and it did work.
Thanks


----------



## freebird1 (Apr 18, 2014)

I swear I did that yesterday and it did not work

Anyways, one more question. Now when I do an `ifconfig em0`, all is correct and it shows my IP address, netmask, and broadcast address.  But on IPv4, I am curious as to why the `ifconfig em0` is showing up as hex instead of what I entered in 255.255.255.0?

Thanks


----------



## asteriskRoss (Apr 19, 2014)

Your /etc/rc.conf looks fine to me and from your latest post I assume that everything is working as it should.  According to the ifconfig(8) man page, you can specify the subnet mask as you are, in hex or even using an alias you configure in /etc/networks (see networks(5)):


> The mask can be specified as a single hexadecimal number with a leading `0x', with a dot-notation Internet address, or with a pseudo-network name listed in the network table


As to why the current configuration display shows the subnet mask in hexadecimal rather than CIDR notation, you would need to ask the developers.  It does allow for consistency between IPv4 and IPv6.


----------

