这是关于在 FreeBSD 系统中创建和配置一个名为wirevnet
的 jail 的详细步骤:
- 创建 jail:使用 Bastille 创建 jail,命令为
bastille create -V [wirevnet](https://wordpress.xmcnetwork.com/?page_id=1452) 14.0-RELEASE 0.0.0.0 bge1
,初始时分配 IP 地址0.0.0.0
,通过bastille cmd wirevnet ifconfig
获取以太网地址并在路由器上创建静态预留。 - 配置主机名和 SSH:为 jail 分配主机名并启用 SSH,使用
adduser
创建用户账户[eldapper]
,通过ssh-copy-id
添加公钥,使用pw mod user [eldapper] -w no
删除密码,编辑sshd_config
文件进行安全设置,如PasswordAuthentication no
等。 配置网络相关参数:
- 在
/etc/rc.conf
文件中进行如下配置:ifconfig_e0b_bastille5_name="vnet0"
,ifconfig_vnet0="inet 192.168.1.254/24 up"
,defaultrouter="192.168.1.254"
,hostname="wirevnet.eldapper.com"
,gateway_enable="YES"
,sshd_enable="YES"
,wireguard_interfaces="wg0"
,wireguard_enable="YES"
,wireguard_ui_enable="YES"
,wgui_enable="YES"
,pf_enable="YES"
,pf_rules="/etc/pf.conf"
。 - 在路由器上创建重定向规则,将
Wireguard Listen Port: 51820
重定向到 jail 的 IP192.168.1.254
。 - 确保主机上的
if_wg
内核模块在系统启动时自动加载,即kld_list="if_wg"
,并在 jail 的jail.conf
文件中添加allow.sysvipc;
以允许模块通过 jail。
- 在
配置 wireguard、wireguard-ui 和 wgui 相关服务:
- 安装 wireguard 工具
pkg install wireguard-tools
,启用 wireguard,在/etc/rc.conf
中添加wireguard_interfaces="wg0"
,wireguard_enable="YES"
。 - 下载 wireguard-ui,从https://github.com/ngoduykhanh/wireguard-ui获取,解压到
/usr/local/etc/wireguard-ui/
。 - 创建 wireguard-ui 启动脚本
/usr/local/etc/rc.d/wireguard-ui
,设置相关参数和命令,使其在系统启动时自动运行,添加到/etc/rc.conf
中并使其可执行chmod +x /usr/local/etc/rc.d/wireguard-ui
。 - 创建环境变量文件并进行配置,包含各种相关信息。
- 为了实现 WireGuard 中添加新客户端后自动重启服务器的功能,安装
inotify-tools
,创建/usr/local/etc/rc.d/wgui
脚本,在其中使用inotifywait
监控/usr/local/etc/wireguard/
目录的变化,自动执行wg-quick down wg0
和wg-quick up wg0
命令,添加到/etc/rc.conf
中并使其可执行chmod +x /usr/local/etc/wgui/wgui
。
- 安装 wireguard 工具
- 配置 pf 防火墙:在 jail 的
/etc/pf.conf
文件中进行如下配置:wireguard_clients="10.10.100.0/24"
,wanint="vnet0"
,wg_ports="{51821}"
,set skip on lo0
,nat on $wanint inet from $wireguard_clients to any -> $wanint
,pass in on $wanint proto udp from any to $wanint port $wg_ports
,pass in on $wanint proto tcp from any to $wanint port 22 keep state
,pass out quick
,pass in on wg0 from any to any
。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。