FreeBSD IP 配置總結

來源:互聯網
上載者:User

本文轉載:http://xnming.blogbus.com/logs/16561419.html

#####
# 手工指定的方式
################################

# ipconfig fxp0 192.168.8.33/24     # 添加網卡ip
# route add default 192.168.8.1     # 添加路由(也可理解為網關)
立即生效,但是重啟後失效。

如何重啟後仍然保持呢?
# ee /etc/rc.conf
ifconfig_fxp0="inet 192.168.8.8 netmask 255.255.255.0 "  # fxp0 網卡地址和子網路遮罩
defaultrouter="192.168.8.10"     # 網關地址
hostname="study.nowire.com.cn"     # 機器名
ifconfig_wi0="inet 192.168.8.55 netmask 255.255.255.0" # wi0 網卡地址,對應無線網卡

修改 /etc/rc.conf 配置之後可以通過如下方式生效:
第一種方法:# sh /etc/rc
第二種方法:# /etc/netstart
第三種方法:重啟機器

#####
# DHCP 方式
################################

在 /etc/rc.conf 中添加:
ifconfig_fxp0="DHCP"
需要根據具體情況指定網卡名稱。

修改 /etc/rc.conf 配置之後可以通過如下方式生效:
第一種方法:# sh /etc/rc
第二種方法:# /etc/netstart
第三種方法:重啟機器

#####
# 關於 DNS 地址的配置
################################

# ee /etc/resolv.conf
nameserver 202.96.209.133
nameserver 202.96.209.5

#####
# 控制網卡的開關
################################

ifconfig fxp0 up
ifconfig fxp0 down

#####
# 路由方面的配置
################################

查看路由
netstat -rn

添加路由(相當於配置gateway)
route add default 192.168.8.1      # 192.168.8.1為網關地址

如果要修改當前路由配置,需要先刪除,再新增一條,當然如果不是同名的,如不是default的可以直接添加
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 notify 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

#####
# 指定 interface 通過 dhcp 擷取 IP
################################

# 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."

#####
# 指定某個 interface 在通過 DHCP 擷取不成功的時候,限定一個固定 IP
################################

方法:
在 /etc/dhclient.conf 中添加
alias {
interface "xl0";
fixed-address 192.168.42.40;
option subnet-mask 255.255.255.0;
}

舉例:
# 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 the
#    defaults are usually fine.
#
alias {
interface "xl0";
fixed-address 192.168.42.40;
option subnet-mask 255.255.255.0;
}

上例的作用是,當 dhclient 不能通過 DHCP server 擷取 IP 時,則使用 192.168.42.40 這個固定 IP。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.