**文書の過去の版を表示しています。**
Linux ルータ
CentOS7をインストールし、1つのNICに192.168.251.204 (enp3s0)、もう一つのNICにOCNから割り当てられた動的なIP (ppp0)が設定されている。
firewall-cmd --get-active-zone firewall-cmd --zone=external --change-interface=ppp0 --permanent firewall-cmd --zone=trusted --change-interface=enp3s0 --permanent firewall-cmd --zone=external --add-forward-port=port=8352:proto=tcp:toport=3389:toaddr=192.168.251.152 4 --permanent firewall-cmd --zone=trusted --add-masquerade --permanent firewall-cmd --reload firewall-cmd --get-active-zone firewall-cmd --list-all --zone=trusted firewall-cmd --list-all --zone=external
firewalldで制御せず、単にポートを転送するだけなら
firewall-cmd --list-all --zone=public firewall-cmd --zone=public --add-port=2222/tcp --permanent firewall-cmd --reload socat tcp-listen:2222,fork tcp-connect:192.168.251.167:3389
firewalldでポート開けるには
firewall-cmd --zone=public --add-port=1187/tcp --permanent firewall-cmd --zone=public --add-port=10050/tcp --permanent #zabbix用 firewall-cmd --permanent --add-service=nfs --zone=internal #nfs firewall-cmd --permanent --add-service=mountd --zone=internal #nfs firewall-cmd --permanent --add-service=rpc-bind --zone=internal #nfs firewall-cmd --reload
PPPoEだと速度が出ないので、普通に192.168.251.xxxとNTT光のLANの間をルーティング
enp3s0がinternalで、enp0s25がpublic(NTT側)
firewall-cmd --permanent --zone=internal --change-interface=enp3s0 firewall-cmd --permanent --zone=internal --add-masquerade firewall-cmd --permanent --direct --add-rule ipv4 nat POSTROUTING 0 -o enp0s25 -j MASQUERADE firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i enp3s0 -o enp0s25 -j ACCEPT firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i enp0s25 -o enp3s0 -m state --state RELATED,ESTABLISHED -j ACCEPT firewall-cmd --reload firewall-cmd --direct --get-all-rules #ルールの確認 firewall-cmd --direct --get-all-rules --permanent #permanentルールの確認
ポート転送をする場合
firewall-cmd --zone=public --add-forward-port=port=1187:proto=tcp:toport=3389:toaddr=192.168.251.150 --permanent firewall-cmd --zone=public --add-forward-port=port=1186:proto=tcp:toport=3389:toaddr=192.168.251.214 --permanent
ポート転送をやめる場合
firewall-cmd --zone=public --remove-forward-port=port=1186:proto=tcp:toport=3389:toaddr=192.168.251.214 --permanent
r251
Ubuntu 20での話。 ufwを有効にした後
sudo ufw allow in from 192.168.0.0/16
で研究室内からのみアクセスを受け入れる。
ルーター化するには
/etc/default/ufw
DEFAULT_FORWARD_POLICY="ACCEPT"
/etc/ufw/sysctl.conf
net.ipv4.ip_forward=1
/etc/ufw/before.rules
# *filterの前あたりに下記を追加 *nat #-Fがあるとufw reloadしたときに古い設定をリセットしてくれる -F :POSTROUTING ACCEPT [0:0] # Forward traffic from eth0 through eth1. -A POSTROUTING -s 192.168.253.0/24 -o enp5s0 -j MASQUERADE #enp5s0がグローバル側 -A PREROUTING -i enp5s0 -p tcp -d 133.11.144.11 --dport 80 -j DNAT --to-destination 192.168.253.163:80 -A PREROUTING -i enp5s0 -p tcp -d 133.11.144.11 --dport 443 -j DNAT --to-destination 192.168.253.163:443 COMMIT
sudo ufw disable && sudo ufw enable
#before.rulesを書き換えたならば sudo systemctl restart ufw.service #転送ルール確認 sudo iptables -t nat -nL
sudo ufw status sudo ufw allow 80 sudo ufw allow 443
sudo nmtui
下記の箇所を変更
│ 送信先/プレフィックス 次のホップ メトリック │ │ │ 192.168.0.0/16_______ 192.168.253.1________ 100_______ <削除> │ │ │ <追加...> │ │ │ │ │ │ <取り消し> <OK> │ │
[X] このネットワークはデフォルトのルートには使用しない │ [X] 自動的に取得されたルートを無視
r251 proxyサーバ構築
apt install squid apache2-utils
/etc/squid/squid.confを編集して、##auth_param basic program...
が書かれているあたりに下記を追加。
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/.htpasswd auth_param basic children 50 auth_param basic realm Squid Basic Authentication auth_param basic credentialsttl 1000 hours acl password proxy_auth REQUIRED http_access allow password
htpasswd -c /etc/squid/.htpasswd suikou
でパスワードを作成。
systemctl restart squid ufw allow 3128
クライアントは次のような感じで設定する。
zabbix_agentd設定
r251やr311からzabbix_agent-3.0.32-linux-3.0-amd64-static.tar.gz
を転送して、/usr/local/以下に解凍する。
cd /usr/local tar vxf zabbix_agent-3.0.32-linux-3.0-amd64-static.tar.gz mv conf/* etc/ rmdir conf sudo nano /usr/lib/systemd/system/zabbix-agent.service #下記のファイルを作る [Unit] Description=Zabbix Agent #After=syslog.target After=network.target [Service] #Environment="CONFFILE=/usr/local/etc/zabbix_agentd.conf" #EnvironmentFile=-/etc/sysconfig/zabbix-agent Type=forking #Restart=on-failure #PIDFile=/run/zabbix/zabbix_agentd.pid #KillMode=control-group #ExecStart=/usr/local/bin/zabbix_agentd -c $CONFFILE ExecStart=/usr/local/sbin/zabbix_agentd #ExecStart=/home/yoshitake/run-zabbix.sh User=yoshitake Group=yoshitake #ExecStop=/bin/kill -SIGTERM $MAINPID #RestartSec=10s [Install] WantedBy=multi-user.target ##### sudo systemctl start zabbix-agent.service sudo systemctl enable zabbix-agent.service
r311にポート転送追加
まずは、firefoxでhttp://192.168.11.1を開いて、admin:31500193でログインし、ポート転送設定を追加する。
sudo nano /etc/ufw/before.rules
で下記を追加する。
-A PREROUTING -i enp10s0 -p tcp --dport 2208 -j DNAT --to-destination 192.168.251.140:22
その後、
sudo ufw reload
r311のIPマスカレード再設定
r311を入れ替えた際、アダプタの名前が変わってenp10s0→eno2になった。 そのため、r311をデフォルトゲートウェイにしているm50v311n1などが外に通信できなくなった。
r311にログインして、
sudo nmtui #IP: 192.168.11.101/24, GW: 192.168.11.1 sudo nano /etc/ufw/before.rules #-A POSTROUTING -s 192.168.251.0/24 -o eno2 -j MASQUERADE sudo ufw disable && sudo ufw enable #これで繋がるようになったけど、nmtuiの結果が反映されていないので、たぶん再起動しておいたほうが本当は良さそう。