注意点
以前の投稿の字数制限のため、
こちらに追加の質問をします。実現したい事等は、以前の投稿を参照して下さい。
(teratailの投稿字数のカウント方法はマルチバイト=2,空白=1としているのでしょうか?)
発生している問題・エラーメッセージ)(その4)
以前の投稿からの続きなので、その4にしました。
rpiを再起動すると、iptablesの設定が消えるため、firewalldを利用する事にしました。また、firewalldの設定ミスでどのnicからもrpiにアクセス不能になるので、
回復nicを設けました。それに伴い、物理nic名を以下のように変更しました。
eth0 -> main-eth
eth1 -> proxy-eth
回復nic : rescue-eth
また、このリンクのownerモジュール一覧にある、「--cmd-owner」により、squidコマンド自体をルーティング対象にしました。しかし、ルート変更以前にproxy接続ができません。
firewalldの設定は、proxynet,rescuenetという2つのzoneを利用し、以下の結果が得られています。
root@raspberrypi:/etc/firewalld# firewall-cmd --get-active-zone proxynet interfaces: main-eth sources: 192.168.0.0/24 rescuenet interfaces: rescue-eth
squidコマンドに対するルートテーブル変更
main_eth_ip=$(ip addr show main-eth|grep -v inet6|awk '/inet/ {print $2}'|cut -d/ -f1) && proxy_eth_ip=$(ip addr show proxy-eth|grep -v inet6|awk '/inet/ {print $2}'|cut -d/ -f1) && proxy_route_tbl=proxygw && proxy_route_tbl_number=201 && echo 1 > /proc/sys/net/ipv4/ip_forward && ##ipコマンドによる一連の設定 && RT_TBL_FILE=/etc/iproute2/rt_tables RT_TBL_STR="$proxy_route_tbl_number $proxy_route_tbl" if [ -z "$(cat $RT_TBL_FILE|grep -a $RT_TBL_STR)" ]; then echo $RT_TBL_STR >> $RT_TBL_FILE fi main_eth_met=203 && proxy_eth_met=202 && ip rule add fwmark 1 table $proxy_route_tbl && ip route add table $proxy_route_tbl default via 192.168.0.1 dev main-eth src $main_eth_ip metric $main_eth_met && ip route add table $proxy_route_tbl default via 192.168.1.1 dev proxy-eth src $proxy_eth_ip metric $proxy_eth_met && ip route add table $proxy_route_tbl 192.168.0.0/24 dev main-eth proto kernel scope link src $main_eth_ip metric $main_eth_met && ip route add table $proxy_route_tbl 192.168.1.0/24 dev proxy-eth proto kernel scope link src $proxy_eth_ip metric $proxy_eth_met && ##firewalldの設定 && firewall-cmd --zone=proxynet --add-rich-rule='rule family="ipv4" source address="192.168.0.0/24" accept' --permanent && firewall-cmd --zone=proxynet --add-rich-rule='rule family="ipv4" source address="192.168.0.0/24" service name="squid" mark set="1"' --permanent # ipコマンド,firewalld 初期化用 ip rule del fwmark 1 table $proxy_route_tbl && ip route del table $proxy_route_tbl default via 192.168.0.1 dev main-eth src $main_eth_ip metric $main_eth_met && ip route del table $proxy_route_tbl default via 192.168.1.1 dev proxy-eth src $proxy_eth_ip metric $proxy_eth_met && ip route del table $proxy_route_tbl 192.168.0.0/24 dev main-eth proto kernel scope link src $main_eth_ip metric $main_eth_met && ip route del table $proxy_route_tbl 192.168.1.0/24 dev proxy-eth proto kernel scope link src $proxy_eth_ip metric $proxy_eth_met && firewall-cmd --zone=proxynet --remove-rich-rule='rule family="ipv4" source address="192.168.0.0/24" accept' --permanent && firewall-cmd --zone=proxynet --remove-rich-rule='rule family="ipv4" source address="192.168.0.0/24" service name="squid" mark set="1"' --permanent
また、変更後のip route,iptables(firewalldは内部的にはiptablesを利用)の設定は、
ip routeの変更後の設定
root@raspberrypi:/# ip route show table main default via 192.168.0.1 dev main-eth src 192.168.0.4 metric 202 default via 192.168.0.1 dev rescue-eth src 192.168.0.8 metric 203 default via 192.168.1.1 dev proxy-eth src 192.168.1.2 metric 204 192.168.0.0/24 dev main-eth proto kernel scope link src 192.168.0.4 metric 202 192.168.0.0/24 dev rescue-eth proto kernel scope link src 192.168.0.8 metric 203 192.168.1.0/24 dev proxy-eth proto kernel scope link src 192.168.1.2 metric 204 root@raspberrypi:/# ip route show table proxygw default via 192.168.1.1 dev proxy-eth src 192.168.1.2 metric 202 default via 192.168.0.1 dev main-eth src 192.168.0.4 metric 203 192.168.0.0/24 dev main-eth proto kernel scope link src 192.168.0.4 metric 203 192.168.1.0/24 dev proxy-eth proto kernel scope link src 192.168.1.2 metric 202
firewalldの設定変更後のiptablesの設定について
字数制限のため、明らかに無関係な「public」ゾーンの非表記や、
(AAA=allow,deny,log)というまとめた表記をしました。
iptables -Lの実行結果
root@raspberrypi:/# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere INPUT_direct all -- anywhere anywhere INPUT_ZONES_SOURCE all -- anywhere anywhere INPUT_ZONES all -- anywhere anywhere DROP all -- anywhere anywhere ctstate INVALID REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere FORWARD_direct all -- anywhere anywhere FORWARD_IN_ZONES_SOURCE all -- anywhere anywhere FORWARD_IN_ZONES all -- anywhere anywhere FORWARD_OUT_ZONES_SOURCE all -- anywhere anywhere FORWARD_OUT_ZONES all -- anywhere anywhere DROP all -- anywhere anywhere ctstate INVALID REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination OUTPUT_direct all -- anywhere anywhere Chain FORWARD_IN_ZONES (1 references) target prot opt source destination FWDI_proxynet all -- anywhere anywhere [goto] Chain FORWARD_IN_ZONES_SOURCE (1 references) target prot opt source destination FWDI_proxynet all -- 192.168.0.0/24 anywhere [goto] Chain FORWARD_OUT_ZONES (1 references) target prot opt source destination FWDO_proxynet all -- anywhere anywhere [goto] Chain FORWARD_OUT_ZONES_SOURCE (1 references) target prot opt source destination FWDO_proxynet all -- anywhere 192.168.0.0/24 [goto] Chain FORWARD_direct (1 references) target prot opt source destination Chain FWDI_proxynet (2 references)(AAA=allow,deny,log) target prot opt source destination FWDI_proxynet_AAA all -- anywhere anywhere ACCEPT icmp -- anywhere anywhere Chain FWDI_proxynet_AAA (1 references) (AAA=allow,deny,log) target prot opt source destination Chain FWDO_proxynet (2 references) (AAA=allow,deny,log) target prot opt source destination FWDO_proxynet_AAA all -- anywhere anywhere Chain FWDO_proxynet_AAA (1 references) (AAA=allow,deny,log) target prot opt source destination Chain INPUT_ZONES (1 references) target prot opt source destination IN_proxynet all -- anywhere anywhere [goto] Chain INPUT_ZONES_SOURCE (1 references) target prot opt source destination IN_proxynet all -- 192.168.0.0/24 anywhere [goto] Chain INPUT_direct (1 references) target prot opt source destination ACCEPT icmp -- anywhere anywhere Chain IN_proxynet (2 references) (AAA=allow,deny,log) target prot opt source destination IN_proxynet_AAA all -- anywhere anywhere ACCEPT icmp -- anywhere anywhere Chain IN_proxynet_allow (1 references) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:3128 ctstate NEW ACCEPT tcp -- anywhere anywhere tcp dpt:ftps ctstate NEW ACCEPT udp -- anywhere 224.0.0.251 udp dpt:mdns ctstate NEW ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ctstate NEW ACCEPT all -- 192.168.0.0/24 anywhere Chain IN_proxynet_AAA (1 references) (AAA=deny,log) target prot opt source destination Chain OUTPUT_direct (1 references) target prot opt source destination
iptables -L -t mangleの実行結果
root@raspberrypi:/# iptables -L -t mangle Chain PREROUTING (policy ACCEPT) target prot opt source destination PREROUTING_direct all -- anywhere anywhere PREROUTING_ZONES_SOURCE all -- anywhere anywhere PREROUTING_ZONES all -- anywhere anywhere Chain AAA (policy ACCEPT) (AAA=FORWARD,INPUT,OUTPUT,POSTROUTING) target prot opt source destination AAA_direct all -- anywhere anywhere Chain AAA_direct (1 references) (AAA=FORWARD,INPUT,OUTPUT,POSTROUTING) target prot opt source destination Chain PREROUTING_ZONES (1 references) target prot opt source destination PRE_proxynet all -- anywhere anywhere [goto] Chain PREROUTING_ZONES_SOURCE (1 references) target prot opt source destination PRE_proxynet all -- 192.168.0.0/24 anywhere [goto] Chain PREROUTING_direct (1 references) target prot opt source destination Chain PRE_proxynet (2 references) (AAA=allow,deny,log) target prot opt source destination PRE_proxynet_AAA all -- anywhere anywhere Chain PRE_proxynet_allow (1 references) target prot opt source destination MARK tcp -- 192.168.0.0/24 anywhere tcp dpt:3128 MARK set 0x1 Chain PRE_proxynet_AAA (1 references) (AAA=deny,log) target prot opt source destination
##具体的な症状
・squid proxyから503のhttpレスポンス
・1.1.1.1宛へのproxy接続を試行すると、src ipがeth1であるリクエストが物理nicがeth0であるインターフェースから送出をtsharkにより確認
補足情報(FW/ツールのバージョンなど)
iptables v1.6.0
squid3-3.5.23
firewalld(確認方法不明)

あなたの回答
tips
プレビュー