# Cannot use pkg_add since setting fix IP in rc.conf



## fred974 (Aug 31, 2011)

Hello everyone,

I'm really really new to unix/linux and I installed FreeBSD by following threse 2 tutorials on youtube:
http://www.youtube.com/watch?v=2St2OApkR1o
http://www.youtube.com/watch?v=fjPyXMcvUCE&feature=related

I have added the following lines in the rc.conf file:

```
ifconfig_de0="inet 192.168.1.178 netmask 255.255.255.0"
default_router="192.168.1.1"
sshd_enable="YES"
hostname="bsdfilesrv"
```

Since I added this in the file, I am unable to use the command pkg_add. I tried `pkg_add -r sudo` and got a message saying


```
error: unable to get [url]ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8.2release/Latest/sudo.tbz:[/url] No address record
pkg_add: unable to fetch [url]ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8.2release/Latest/sudo.tbz:[/url] by URL
```

I am able to ping all the pc on my network as well as google.com but when installing ports and packages I get this frustrating error.

I have also read other tutorial where they typed defaultrouter instead of default_router. I also read to modify the resolv.conf and hosts file but I am getting nowhere.

Here is some data:


```
#cat /etc/resolv.conf
nameserver 192.168.1.1
#cat /etc/hosts
::1	localhost localhost.mydomain
127.0.0.1	localhost localhost.mydomain
```
If I comment out all the setting that I added in the rc.conf file and do `dhclient em0` then, I can use pkg_add again.


Could somebody out help me please 


Thank you all in advance

Frederic


----------



## DutchDaemon (Aug 31, 2011)

You're referring to de0 and em0 in the same post. Make sure you send commands to the right NIC. If you can/should use DHCP, just use that instead of setting your own IP address. DHCP should also take care of a proper nameserver entry in resolv.conf.

If your NIC is indeed de0, set this in /etc/rc.conf:


```
ifconfig_de0="DHCP"
or
ifconfig_de0="SYNCDHCP"
```

and take out the defaultrouter setting (this should be supplied by DHCP as well). If it's actually em0, adjust accordingly.

After a reboot your DHCP server/gateway should provide you with the proper settings for IP address, default gateway, and nameserver(s).


----------



## fred974 (Aug 31, 2011)

Hi, thank you for your prompt response, do i need to add 

```
synchronous_dhclient="YES"
```


----------



## fred974 (Aug 31, 2011)

Hi DutchDaemon,

I just done ifconfig and can confirm that the NIC is em0.
I have also removed 
	
	



```
default_router="192.168.1.1"
```
 and added 
	
	



```
ifconfig_em0="SYNCDHCP"
```
 and rebooted from the console. The problem is still the same. I added 
	
	



```
synchronous_dhclient="YES"
```
 rebooted and still the same problem
BTW, all of the above were done as root. I also noticed that i do not have the most recent history in the terminal but the oldish one. Don't know if that help in my problem.


----------



## kpa (Aug 31, 2011)

It's not default_router but defaultrouter:


```
defaultrouter="192.168.1.1"
```

You can fix that in /etc/rc.conf and set the new default route without rebooting if you do this as root:

`# /etc/rc.d/routing start`

Verify with `# netstat -nr` that you have a correct default route.


----------



## fred974 (Aug 31, 2011)

rc.conf


```
keymap="uk.iso"
ifconfig_em0="SYNCDHCP"
synchronous_dhclient="YES"
sshd_enable="YES"
```

I saved the file and do
`# /etc/rc.d/routing start`
The problem is still the same.
`# netstat -nr`


----------



## fred974 (Aug 31, 2011)

Hi Kpa,

I tried that and still not working. Also tried with 
	
	



```
ifconfig_em0="SYNCDHCP"
```


----------



## wblock@ (Aug 31, 2011)

Running dhclient em0 is equivalent to ifconfig_em0="SYNCDHCP".

Please show the entire contents of /etc/rc.conf.


----------



## DutchDaemon (Aug 31, 2011)

Also: after rebooting with (SYNC)DHCP active, see if you can ping the default gateway as it shows up in [cmd=]netstat -rn[/cmd] and post here what DHCP put in /etc/resolv.conf. And please format your posts.


----------



## SirDice (Aug 31, 2011)

Remove the 192.168.1.66 address from lo0.


----------



## kpa (Aug 31, 2011)

SirDice said:
			
		

> Remove the 192.168.1.66 address from lo0.



I think you're mistaken here. My understanding is that the Netif column says:
"use this interface for selecting the source address for connections when the destination address matches this entry in the routing table". So in this case the entry for 192.168.1.66 in the routing table is what should be there.


----------



## SirDice (Aug 31, 2011)

Errrm, yes, you are correct. I should think before I type...

It would really help immensely if the OP would post his /etc/rc.conf.


----------



## wblock@ (Aug 31, 2011)

SirDice said:
			
		

> It would really help immensely if the OP would post his /etc/rc.conf.



Post #6 may already show it.  I don't think restarting routing is enough, though, and would go with
`# [del]service restart netif[/del]`
`# service netif restart`

What we still need to see is the output of
`# ifconfig`
after manually running dhclient(8), when it's working.  I'm thinking the LAN might not actually be 192.168.1.0/24.


----------



## SirDice (Sep 1, 2011)

It's only been posted in parts 

Getting an error in /etc/rc.conf might be the reason it's not working properly.


----------



## fred974 (Sep 1, 2011)

Good morning all.

I'll like to say thank you for all your effort in trying to help me in resolving my problem.
Sorry if my post seem to be posted in 'parts' but i am very new to lunix/freebsd(2 weeks to be precise)
I attached the screenshots of all the information you've asked me.


----------



## wblock@ (Sep 1, 2011)

Sorry, I got that command backwards.  Should have been
`# service netif restart`

Use script(1) to capture sessions.


```
synchronous_dhclient="YES"
ifconfig_em0="DHCP"
```
is the same thing as

```
ifconfig_em0="SYNCDHCP"
```

The ping in #15 is working, so this was after running dhclient(8).

The static IP settings for em0 and defaultrouter plus manually entering nameservers in /etc/resolv.conf should be enough.  A few warnings:

1.  Make sure dhclient(8) is dead before you switch to a static address.  It is in control of what goes in /etc/resolv.conf and can overwrite what you enter there manually.  Kill it with pkill dhclient.  Restarting netif or rebooting will do it also.
2.  Make sure the static address you want is allowed by the network.  Not everything is /24.
3.  Technically, the static address you choose should be outside of the range assigned by DHCP.  In practice, good DHCP servers will check if an address is already in use before handing it out.


----------



## fred974 (Sep 1, 2011)

wblock,

I will try your sugestion asap. Could you tell me how can i find out what is my nameserver?


----------



## wblock@ (Sep 1, 2011)

Running dhclient(8) will set the nameserver in /etc/resolv.conf.  According to #15, it's 192.168.1.1.  As an alternate, you could use your ISP's nameservers directly, or even http://code.google.com/speed/public-dns/.


----------



## fred974 (Sep 1, 2011)

Sorry, still not working. I done the same installed on a normal pc and it work with no problem. is the problem because i use esxi from vware?


----------



## fred974 (Sep 1, 2011)

here is what i've done:
i cleared the entire file and added 

```
keymap=uk.iso"
ifconfig_em0="SYNCDHCP"
```
then
[cmd=]service netif restart[/CMD]
my resolv.conf is showing 

```
nameserver 192.168.1.1
```

I can still ping google or my other pc.
Is it a problem with vm?


----------



## wblock@ (Sep 1, 2011)

A) Use  tags for filenames, 
	
	



```
tags for code.

B) If it works on real hardware but fails on a VM, yes, that indicates the VM software or host is the problem.  Using VM software should have been mentioned earlier.
```


----------



## fred974 (Sep 1, 2011)

Yes, sorry i forgot to mention. I'm trying to install it on esxi 4.1 and its freebsd amd64


----------



## wblock@ (Sep 1, 2011)

I have not used VMware in a long time.  Check the network mode in the VM software: NAT, bridged, etc.  For the VM guest to act like just another machine on the network, use bridged.


----------

