我正在尝试将 aws ec2 实例中的 jail 连接到互联网。我能够创建 jail 并在其中执行控制台,问题是 jail 与外部没有任何连接。
这是创建监狱的步骤:
echo 'cloned_interfaces="lo1"' >> /etc/rc.conf
service netif cloneup
ezjail-admin create jail 'lo1|127.0.1.1,xn0|172.31.36.57'
cp /etc/resolv.conf /usr/jails/jail/etc
ezjail-admin console -f jail
之后,如果我尝试使用 pkg 进行任何安装:
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:12:amd64/quarterly, please wait...
pkg: Error fetching http://pkg.FreeBSD.org/FreeBSD:12:amd64/quarterly/Latest/pkg.txz: No address record
Address resolution failed for http://pkg.FreeBSD.org/FreeBSD:12:amd64/quarterly.
Consider changing PACKAGESITE.
查看主机 ifconfig 的输出:
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
groups: lo
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
xn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 9001
options=503<RXCSUM,TXCSUM,TSO4,LRO>
ether 06:26:aa:da:23:d2
inet6 fe80::426:aaff:feda:23d2%xn0 prefixlen 64 scopeid 0x2
inet 172.31.36.56 netmask 0xfffff000 broadcast 172.31.47.255
inet 172.31.36.57 netmask 0xffffffff broadcast 172.31.36.57
media: Ethernet manual
status: active
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
lo1: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
inet6 fe80::1%lo1 prefixlen 64 scopeid 0x3
inet 127.0.1.1 netmask 0xffffffff
groups: lo
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
我认为我给接口的第二个 IP 无效。
您知道从监狱获得连接的方式是什么吗?
答案1
使用 pf 使连接正常工作
ext_if="xn0"
jail_net="127.0.1.1"
nat pass on $ext_if from $jail_net to any -> $ext_if
pass out
pass in