linuxルータ構築

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
linuxルータ構築 [2023/07/13 15:51] suikoulinuxルータ構築 [Unknown date] (現在) – 削除 - 外部編集 (Unknown date) 127.0.0.1
行 1: 行 1:
-# Linux ルータ 
- 
-# Rocky Linux 9編 
- 
-設定初期化 
- 
-``` 
-sudo systemctl stop firewalld 
-sudo rm -rf /etc/firewalld 
-sudo cp -rp /usr/lib/firewalld /etc/ 
-sudo systemctl start firewalld 
-``` 
- 
-eth0が外、eth1が内の場合 
- 
-``` 
-firewall-cmd --zone=external --change-interface=eth0 --permanent 
-firewall-cmd --zone=internal --change-interface=eth1 --permanent 
-# -- -- 
-firewall-cmd --permanent --new-policy natPolicy 
-firewall-cmd --permanent --policy natPolicy --set-target ACCEPT 
-firewall-cmd --permanent --policy natPolicy --add-egress-zone external 
-firewall-cmd --permanent --policy natPolicy --add-ingress-zone internal 
-firewall-cmd --reload 
-``` 
- 
-port転送 外からの8022ポートを内側の192.168.1.2:22に転送 
- 
-``` 
-firewall-cmd --zone=external --add-forward-port=port=8022:proto=tcp:toport=22:toaddr=192.168.1.2 
-``` 
- 
-# CentOS7編(old) 
-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 
-``` 
-## CentOS7編 2023 (失敗) 
- 
-``` 
-sudo nmtui 
-``` 
- 
-で2つのNICを設定。デフォルトゲートウェイにしないほうに、「デフォルトゲートウェイにしない」にチェックを入れておく。それ以外は同じ設定をして 
- 
-``` 
-sudo systemctl restart network 
-``` 
- 
-でネットワーク接続を変更。```route```コマンドで変更を確認。 
- 
-``` 
-sudo nano /etc/sysctl.conf 
-``` 
- 
-で、ファイルの最後に 
- 
-``` 
-net.ipv4.ip_forward=1 
-``` 
- 
-を追加してOSを再起動。 
- 
-``` 
-cat /proc/sys/net/ipv4/ip_forward 
-``` 
- 
-で1と表示されるか確認。(変更前は0) 
-でも、この手順では他のPCからルーターとして使用するのはダメだったので、oldの手順で行う必要がありそう。 
- 
- 
-## r301 (Ubuntu22) 
- 
-``` 
-sudo su - 
-ufw allow in from 192.168.0.0/16 
-ufw enable 
- 
-nano /etc/default/ufw 
-#下記に変更 
-DEFAULT_FORWARD_POLICY="ACCEPT" 
- #DROP 
- 
-nano /etc/sysctl.conf 
-#コメント解除 
-net.ipv4.ip_forward=1 
- 
-sysctl -p 
-ufw reload 
- 
-ufw status verbose 
-nano /etc/ufw/before.rules 
-# 最終行のCOMMITの後に追記 
-# NTT側 enp14s0 192.168.11.101/24 
-# ラボ側 enp9s0 192.168.200.101/20 
- 
-# NAT 
-*nat 
--F 
-:POSTROUTING ACCEPT [0:0] 
--A POSTROUTING -s 192.168.192.0/20 -o enp14s0 -j MASQUERADE 
- 
-COMMIT 
-``` 
- 
-``` 
-ufw reload 
- 
-ufw allow ssh 
- 
-``` 
- 
-zabbixのインストール 
- 
-``` 
-apt install -y build-essential  
-wget https://cdn.zabbix.com/zabbix/sources/oldstable/3.2/zabbix-3.2.11.tar.gz 
-tar vxf zabbix-3.2.11.tar.gz 
-cd zabbix-3.2.11 
-./configure --prefix=/usr/local/zabbix-3.2.11 --enable-agent 
-make -j 8 install 
-sed -i 's/=127.0.0.1/=192.168.200.202/' /usr/local/zabbix-3.2.11/etc/zabbix_agentd.conf 
-cat << 'EOF' >> /usr/local/zabbix-3.2.11/etc/zabbix_agentd.conf 
-Timeout=30 
-UserParameter=hdd.rmbyte[*],iostat -mdx 1 2 | grep $1 | awk '{print $$6}'|tail -n 1 
-UserParameter=hdd.wmbyte[*],iostat -mdx 1 2 | grep $1 | awk '{print $$7}'|tail -n 1 
-UserParameter=toppro,top -b -n 1 | sed -e "1,6d" | head -6|awk '{print $2" "$9" "$10" "$12}' 
- 
-EOF 
- 
-cat << 'EOF' >> /usr/lib/systemd/system/zabbix-agent.service 
-/usr/local/zabbix-3.2.11/zabbix-agent.service 
-[Unit] 
-Description=Zabbix Agent 
-After=syslog.target 
-After=network.target 
- 
-[Service] 
-Environment="CONFFILE=/usr/local/zabbix-3.2.11/etc/zabbix_agentd.conf" 
-EnvironmentFile=-/etc/sysconfig/zabbix-agent 
-Type=simple 
-KillMode=process 
-ExecStart=/usr/local/zabbix-3.2.11/sbin/zabbix_agentd -c $CONFFILE -f 
-ExecStop=/bin/kill $MAINPID 
-User=zabbix 
- 
-[Install] 
-WantedBy=multi-user.target 
- 
-EOF 
- 
-groupadd -g 603 zabbix 
-useradd -u 603 -g 603 zabbix 
-systemctl enable --now zabbix-agent.service 
-``` 
- 
-## r251 (Ubuntu20) 
- 
-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 
-``` 
- 
-クライアントは次のような感じで設定する。 
- 
-{{:pasted:20210421-003648.png}} 
- 
-### 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の結果が反映されていないので、たぶん再起動しておいたほうが本当は良さそう。 
-``` 
- 
- 
- 
  
  • linuxルータ構築.1689263464.txt.gz
  • 最終更新: 2023/07/13 15:51
  • by suikou