WireGuard VNET 监狱

这是关于在 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 wg0wg-quick up wg0命令,添加到/etc/rc.conf中并使其可执行chmod +x /usr/local/etc/wgui/wgui
  • 配置 pf 防火墙:在 jail 的/etc/pf.conf文件中进行如下配置:wireguard_clients="10.10.100.0/24"wanint="vnet0"wg_ports="{51821}"set skip on lo0nat on $wanint inet from $wireguard_clients to any -> $wanintpass in on $wanint proto udp from any to $wanint port $wg_portspass in on $wanint proto tcp from any to $wanint port 22 keep statepass out quickpass in on wg0 from any to any
阅读 35
0 条评论