
Linux基础
1 前言
一个问题,一篇文章,一出故事。
笔者想使用freeBSD打造一款路由器,于是整理此文。
本章将完成freeBSD的基本设置。
2 最佳实践
2.1 网络基本配置
2.1.1 查看网卡接口名字
ifconfig
2.1.2 设置临时IP
ifconfig vtnet0 10.168.0.80 netmask 255.255.255.0 route add default 10.168.0.1
接口设置后,你需要使用如下命令启用或重启接口,
ifconfig vtnet0 up # 启用网卡 ifconfig vtnet0 down # 禁用网卡
2.1.3 设置永久IP
vi /etc/rc.conf
加入如下配置,
# 启用网卡 ifconfig_vtnet0="inet 10.168.0.80 netmask 255.255.255.0" # 设置默认网关 defaultrouter="10.168.0.1"
另外,如果需要使用DHCP获取IP地址,请使用如下设置,
ifconfig_vtnet0="DHCP"
重启服务使配置生效,
service netif restart # 重启网络接口 service routing restart # 重启路由
测试配置,
ping 10.168.0.1 # 测试局域网网关 netstat -rn #检查路由表
2.2 设置DNS
2.2.1 临时设置
touch /etc/resolv.conf chmod 644 /etc/resolv.conf vi /etc/resolv.conf
加入如下设置,
nameserver 202.96.128.86 nameserver 202.96.128.166
2.2.2 测试配置
ping www.cmdschool.org
2.3 设置主机名称
2.3.1 临时设置
hostname dgrouter.cmdschool.org
2.3.2 设置永久IP
vi /etc/rc.conf
加入如下配置,
hostname="dgrouter.cmdschool.org"
2.4 允许root登陆
2.4.1 修改配置
vi /etc/ssh/ssh_config
加入如下设置,
PermitRootLogin yes
2.4.2 重启服务使配置生效
service sshd restart
2.5 检查源并安装
2.5.1 临时设置
cat /etc/pkg/FreeBSD.conf
加入如下设置,
# To disable this repository, instead of modifying or removing this file, # create a /usr/local/etc/pkg/repos/FreeBSD.conf file: # # mkdir -p /usr/local/etc/pkg/repos # echo "FreeBSD: { enabled: no }" > /usr/local/etc/pkg/repos/FreeBSD.conf # FreeBSD: { url: "pkg+https://pkg.FreeBSD.org/${ABI}/quarterly", mirror_type: "srv", signature_type: "fingerprints", fingerprints: "/usr/share/keys/pkg", enabled: yes } FreeBSD-kmods: { url: "pkg+https://pkg.FreeBSD.org/${ABI}/kmods_quarterly_${VERSION_MINOR}", mirror_type: "srv", signature_type: "fingerprints", fingerprints: "/usr/share/keys/pkg", enabled: yes }
更新软件包缓存,
pkg update -f
2.5.2 查找软件包并安装
pkg search vim pkg install vim
2.6 配置ntp客户端
2.6.1 安装软件包
pkg install -y chrony
2.6.2 确认或修改修改配置
cat /usr/local/etc/chrony.conf
2.6.3 启动服务并设置服务自启动
service chronyd start sysrc chronyd_enable="YES"
2.6.4 强制同步和监控统计信息
chronyc makestep chronyc sourcestats
没有评论