イーサネット ブリッジの新しいインスタンスを作成する場合:
# brctl addbr br1
# ip link set dev br1 up
# ip addr add 10.100.100.1/24 dev br1
デフォルトのポート 8888 でtinyproxy
リッスンを開始します。localhost
# tinyproxy
新しいネットワーク名前空間を作成しfirejail
、ブリッジに接続します。
# firejail --net=br1 /bin/bash
tinyproxy
では、たとえば がサンドボックスcurl
内から Web ページを取得するように、ブリッジを介して へのトラフィックをルーティングするにはどうすればよいでしょうかfirejail
。
# curl --proxy http://10.100.100.1:8888 http://wtfismyip.com/text
答え1
次のコマンドは、チェーンをフラッシュ/削除して無効にするのに役立ちますufw
。
# /lib/ufw/ufw-init flush-all
イーサネット ブリッジを作成します。
ext_if="enp8s8"
bridge="brtp8888"
proxy_port="8888" # tinyproxy default
brctl addbr "${bridge}"
ip link set dev "${bridge}" up
ip addr add 10.100.100.1/24 dev "${bridge}"
# Allow the bridge to route traffic to localhost
sysctl net.ipv4.conf."${bridge}".route_localnet=1
ブリッジのポート 8888 宛の TCP トラフィックを次の場所にルーティングしますtinyproxy
:
iptables -t nat -A PREROUTING -i "${bridge}" -p tcp -j DNAT --to-destination 127.0.0.1:"${proxy_port}"
iptables -t nat -A POSTROUTING -s 10.100.100.0/24 -o eth0 -j MASQUERADE
(注:上記はTor を使った Firejail の使い方。
localhost
Tinyproxy は、設定行がない限り接続を制限します。編集/etc/tinyproxy.conf
:
Allow 10.100.100.0/24
より完全な iptables ルールのセット:
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i "${bridge}" -p tcp --dport "${proxy_port}" -j ACCEPT
iptables -t nat -A PREROUTING -i "${bridge}" -p tcp -j DNAT --to-destination 127.0.0.1:"${proxy_port}" # tinyproxy default
iptables -t nat -A POSTROUTING -s 10.100.100.0/24 -o eth0 -j MASQUERADE
同等のものufw
:
## Copy the following into /etc/ufw/before.rules (see man ufw-framework, 'Port Redirections')
# *nat
# :PREROUTING ACCEPT [0:0]
# -A PREROUTING -p tcp -i brtp8888 --dport 8888 -j DNAT \
# --to-destination 127.0.0.1:8888
# COMMIT
# *nat
# :POSTROUTING ACCEPT [0:0]
# -A POSTROUTING -s 10.100.100.0/24 -o eth0 -j MASQUERADE
# COMMIT
ufw allow in on "${bridge}" from 10.100.100.0/24 proto tcp
こちらの投稿もご覧くださいFirejailとホストOpenVPNクライアントを介したインターネットへの接続。
上記のようにブリッジを作成し、 で Firefox を実行しているサンドボックスを開き--net=br1
、Firefox の HTTP プロキシをゲートウェイ IP (つまり、br1
任意のポート) に設定すると機能する理由を説明できる方がいたら、ぜひ知りたいと思います。