常常因為作業, 實驗, 或個人需求架設伺服器,但面臨的一個問題就是手上沒有 public IP,該如何是好
這時我們就會需要 NAT Server 來幫助我們將 private network 轉到 public network 啦
本篇介紹在 VMware Esxi 上用 FreeBSD+pf 架設一台 NAT Server 為 gateway,讓其餘虛擬機可已不需要拿 public 連上網路
ifconfig_em0="inet 140.113.24.188 netmask 255.255.255.224" defaultrouter="140.113.24.161" ifconfig_em1="inet 192.168.1.253 netmask 255.255.255.0" pf_enable="YES" pflog_enable="YES" gateway_enable="YES"
# /etc/rc.d/netif restart # /etc/rc.d/routing restart
ext_if="em0" int_if="em1" lan_net="192.168.1.0/24" table <ssh_bruteforce> persist table <trusted> {} set skip on lo0 scrub in all nat on $ext_if from $lan_net to any -> 140.113.24.188 no nat on $ext_if from !$lan_net to any block drop in quick on $ext_if from <ssh_bruteforce> to any pass in quick on $ext_if from <trusted> to any
gateway_enable=“YES” 可用下列指令在不重開機下執行
# sysctl net.inet.ip.forwarding=1
# service pf restart
這樣一台 NAT Server 基本就能運作了