I had this problem when I missed the FreeBSD internet configure:
ping google.com ... ping: cannot resolve google.com: Host name lookup failure
There is no internet access because computer not assigned ip address and gateway ip.
There are two ways to solve the problem.
The first is to set the ip address and gateway address manually.
The second solution is to run dhclient that will configure internet parameters itself, automatically and will work in the background. This method is better when the computer has a dynamic ip and there are several devices on the network. It is especially convenient to use it if you use internet access via Wi-Fi.
Automatic Internet setup using dhclient
Need to know the name of the internet interface. Need to execute the command for this. There are several utilities for this we can use any.
On FreeBSD it is popular to use ifconfig:
The interface name looks like “em0”, so it is easy to find. Note that lo0 is loopback network interface, it’s not what we need.
On Linux usually use the following command:
sudo ip addr show ... 2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
In my case the interface name is enp4s0.
Then we need to run dhclient with the name of interface as a parameter.
Use the following command on FreeBSD (don’t forget to replace the interface name with your own) :
dhclient -b em0
In this way we can make it on Linux (don’t forget to replace the interface name with your own):
sudo dhclient enp4s0
This may differ on the version of dhclient, but all we need to do is run dhclient.
Now we can make sure that the Internet works using ping:
To run dhclient when the system starts it can be added to the system crontab. Make sure you run crontab with superuser (root) privileges:
sudo crontab -e
Then add the following line (replace with your interface).
@reboot /sbin/dhclient -b em0
@reboot /sbin/dhclient enp4s0
Save changes and reboot, make sure the Internet is working now.
Manual Internet setup
In general, it looks like this.
ifconfig em0 192.168.0.65 netmask 255.255.255.0 up (Need to replace ip address, interface name and mask) route add default 192.168.0.1 (Replace the gateway address with your)
Linux commands (since now many Linux distributions use ip utility instead ifconfig):
sudo ip a add 192.168.0.65/255.255.255.0 dev enp4s0 (Need to replace ip address, interface name and mask) sudo ip link set dev enp4s0 up sudo ip route add default via 192.168.0.1 (Replace the gateway address with your)
The first command assigns an IP address to the interface. The second command assigns the default IP address of the gateway.
To make these settings work with every start of the system, we can add this to the system crontab (run it with root privileges):
sudo crontab -e
Add your commands to this by sharing them with appersands (&&):
@reboot /sbin/ifconfig em0 192.168.0.65 netmask 255.255.255.0 up && /sbin/route add default 192.168.0.1