本文将介绍在FreeBSD 12系统上设置主机名和静态IP地址的方法,它运行在Linux虚拟机VirtualBox里,安装方法请参考在Ubuntu 18.04/Debian 9上安装VirtualBox 6.0的方法。
运行ifconfig命令
请注意,FreeBSD网络接口标识符使用驱动程序名称后跟一个数字:
# ifconfig
em0: flags=8843 metric 0 mtu 1500
options=81009b
ether 08:00:27:12:6b:98
inet 10.0.0.11 netmask 0xffffff00 broadcast 10.0.0.255
media: Ethernet autoselect (1000baseT )
status: active
nd6 options=29
lo0: flags=8049 metric 0 mtu 16384
options=680003
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
inet 127.0.0.1 netmask 0xff000000
groups: lo
nd6 options=21
要在FreeBSD 12服务器上拥有静态的IP地址,必须将IP地址分配给接口,并在/etc/rc.conf中包含IP配置,我们来看一个例子如下:
设置服务器静态主机名:freebsd.example.com。
设置接口IP地址:192.168.13.4/24。
将接口的网关设置为:192.168.13.1。
在FreeBSD 12上设置主机名
使用以下命令在FreeBSD 12上设置主机名:
$ su -
# hostname freebsd.example.com
# echo ""hostname=freebsd.example.com"" >> /etc/rc.conf
如果dhclient用于通过DHCP设置主机名,则hostname变量应设置为空字符串。
在FreeBSD 12上设置静态IP地址
现在你已设置主机名,继续在FreeBSD 12系统上配置静态IP地址:
# vi /etc/rc.conf
增加以下代码:
ifconfig_em0="inet 192.168.13.4 netmask 255.255.255.0"
defaultrouter="192.168.13.1"
重启FreeBSD网络服务和路由表:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart
要为DHCP配置接口,请将设置重置为:
ifconfig_em0="DHCP"
相关主题