Free BSD网卡设置

    基本配置网卡IP与网关的配置文件是目录/etc下面的rc.conf文件.在配置之前请使用ifconfig -a来查看正确的网卡名,本人的是em0,
1.使用ipconfig
# ipconfig em0 192.168.56.102/24     # 添加网卡ip
# route add default 192.168.56.1     # 添加路由(也可理解为网关)
立即生效,但是重启后失效。
2.修改/etc/rc.conf配置文件,重启后仍然保持
# vi /etc/rc.conf
ifconfig_em0="inet 192.168.56.106 netmask 255.255.255.0 "   # em0 网卡地址和子网掩码
defaultrouter="192.168.56.1"      # 网关地址
hostname="test"      # 机器名
 
修改 /etc/rc.conf 配置之后可以通过如下方式生效:
第一种方法:# sh /etc/rc
第二种方法:# /etc/netstart
第三种方法:重启机器
 
#####
# DHCP 方式
################################
在 /etc/rc.conf 中添加:
ifconfig_em0="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 em0 up
ifconfig em0 down
#####
# 路由方面的配置
################################
查看路由
netstat -rn
添加路由(相当于配置gateway)
route add default 192.168.56.1      # 192.168.56.1为网关地址
如果要修改当前路由配置,需要先删除,再新增一条,当然如果不是同名的,如不是default的可以直接添加
route delete default 192.168.56.1
route add default 192.168.56.1
#####
# 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 em0    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 "em0";
fixed-address 192.168.56.180;
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 "em0";
fixed-address 192.168.56.180;
option subnet-mask 255.255.255.0;
}
上例的作用是,当 dhclient 不能通过 DHCP server 获取 IP 时,则使用 192.168.56.180 这个固定 IP。

转载于:https://my.oschina.net/amoshuang/blog/76389

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值