This article reprinted: http://xnming.blogbus.com/logs/16561419.html
#####
# Manually specified Method
################################
# Ipconfig fxp0 192.168.8.33/24 # Add the nic ip Address
# Route add default 192.168.8.1 # Add a route (also known as a gateway)
Takes effect immediately, but becomes invalid after restart.
How can I keep it after restart?
# Ee/etc/rc. conf
Ifconfig_fxp0 = "Inet 192.168.8.8 netmask 255.255.255.0" # fxp0 NIC address and subnet mask
Defaultrouter = "192.168.8.10" # gateway address
Hostname = "study.nowire.com.cn" # machine name
Ifconfig_wi0 = "Inet 192.168.8.55 netmask 255.255.255.0" # wi0 NIC address, corresponding to wireless Nic
After modifying the/etc/rc. conf configuration, it can take effect as follows:
Method 1: # sh/etc/rc
Method 2: #/etc/netstart
Method 3: restart the machine
#####
# DHCP Mode
################################
Add the following in/etc/rc. conf:
Ifconfig_fxp0 = "DHCP"
You need to specify the NIC name based on the actual situation.
After modifying the/etc/rc. conf configuration, it can take effect as follows:
Method 1: # sh/etc/rc
Method 2: #/etc/netstart
Method 3: restart the machine
#####
# DNS Address Configuration
################################
# Ee/etc/resolv. conf
Nameserver 202.96.209.20.
Nameserver 202.96.209.5
#####
# Nic control switch
################################
Ifconfig fxp0 up
Ifconfig fxp0 down
#####
# Routing configuration
################################
View routes
Netstat-Rn
Add a route (equivalent to configuring gateway)
Route add default 192.168.8.1 #192.168.8.1 is the gateway address
If you want to modify the current route configuration, You need to delete it and add another one. Of course, if it is not the same name, you can directly add it if it is not the default one.
Route delete default 192.168.8.1
Route add default 192.168.8.10
#####
# DHCP release
################################
# Dhclient-r release the current lease and exit the client.
Here's a clip of dhclient from the FreeBSD man pages;
"The client normally doesn't release the current lease as it is not required by the DHCP protocol. some cable ISPs require their clients to handle y the server if they wish to release an assigned IP address. the-r flag explicitly releases the current lease,
And once the lease has been released, the client exits ."
If you are getting kill: xxxx: no such process this means the dhclient process was already stopped
#####
# Specifying an interface to obtain an IP address through DHCP
################################
# Dhclient xl0 starts the dhclient process for interface xl0
I think its a good idea to specify an interface otherwise you may notice your/var/log/messages filling up with "dhclient: send_packet: address family not supported by protocol family"
Here's a clip of dhclient from the FreeBSD man pages;
"If no interface names are specified on the command line dhclient will normally identify all network interfaces, elimininating non-broadcast interfaces if possible, and attempt to configure each interface ."
#####
# Specify a fixed IP address when an interface fails to be obtained through DHCP.
################################
Method:
Add/etc/dhclient. conf
Alias {
Interface "xl0 ";
Fixed-address 192.168.42.40;
Option subnet-mask limit 255.0;
}
Example:
# Ee/etc/dhclient. conf
# $ FreeBSD: src/etc/dhclient. conf, V 1.2.2.1 2001/12/14 11:44:31 rwatson exp $
#
# This file is required by the isc dhcp client.
# See ''man 5 dhclient. conf'' for details.
#
# In most cases an empty file is sufficient for most people as
# Defaults are usually fine.
#
Alias {
Interface "xl0 ";
Fixed-address 192.168.42.40;
Option subnet-mask limit 255.0;
}
In the above example, when the dhclient cannot obtain the IP address through the DHCP server, it uses the fixed IP address 192.168.42.40.