CentOS7でルータを作ってみる
作り方としては
らがありそう. 当然どちらも2枚のnicを持たせる必要がある.
「NATPなルータ」を採用するとその内部ネットワークのPCへの措置(proxyとか)は不要. まぁーお手軽だけどルータ越しのActiveDirectoryができないみたい.
「普通なルータ」ならその親元ルータへの調整が別途必要. 権限があればいいが、、なければproxyらを合わせて設置する必要があるみたい.
ここでは下記のようにするため 2枚目nicには 10.10.0.254 を割り当てる

nicへの割り当ては下記のようにする
| Device | IP Address | Gateway | DNS servers | Search domain |
| eth0 | 192.168.0.100/24 | 192.168.0.1 | 192.168.0.3 | sybyl.local |
| eth1 | 10.10.0.254/24 |
ipコマンドの結果は下記になる
[root@gate ~]# ip route
default via 192.168.0.1 dev eth0 proto static metric 100
10.10.0.0/24 dev eth1 proto kernel scope link src 10.10.0.254 metric 101
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.100 metric 100
[root@gate ~]#「10.10.0.0/24」から直接外部へアクセスさせるなら「ip_forward」を有効にします
*別に門であるルータ(10.10.0.254)にあるデータしか使わないのなら設定は不要
[root@gate ~]# cat /proc/sys/net/ipv4/ip_forward
0
[root@gate ~]# echo 1 > /proc/sys/net/ipv4/ip_forward *一時的なら
[root@gate ~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf *恒久的なら
[root@gate ~]# /sbin/sysctl -p加えてfirewallを無効にします.
*もしルータ内部の特定マシン(windowsXP,windows7ら)を門外不出とかに制限するならrouter/iptbles
[root@gate ~]# systemctl stop firewalld
[root@gate ~]#そして大本のルータ(192.168.0.1)に静的ルーティングを加える。

これでルータ内部から外部へ直接アクセスが可能になる.
っが、この大本のルータを弄るのは手続きとか、、まぁー無理な事が多いかな.
その場合は、作った「普通なルータ」にdnsとproxyを乗せて内部LANへの融通を図る.
内部LANの計算機にはdnsの参照先は「普通なルータ」. yumらのproxy設定も必要でrouter/Squid参照
CentOS6に於いてiptablesを駆使してNATPやらポートフォワードやらの定義スクリプトが使えない...
CentOS7ではfirewalldでNATPらを定義するみたい。このfirewalldだが、用途別のネットワークゾーンが
予め用意されている。2つのNICを適切なゾーンに割り当てれば、それでNATPが完成するみたい。
firewalldで提供されているゾーンは9種
ここでは外側に曝された1枚目nicを「external」、内部となる2枚目nicを「trusted」にします

現在の各nicの所属は
[root@e ~]# firewall-cmd --get-active-zone
public
interfaces: enp3s0 enp4s0
[root@e ~]#と「public」ゾーンに所属している。「enp3s0」を「external」へ。「enp4s0」を「trusted」へそれぞれ移す
[root@e ~]# nmcli connection modify enp3s0 connection.zone external
[root@e ~]# nmcli connection modify enp4s0 connection.zone trusted
(別法: firewall-cmd --zone=trusted --add-interface=enp1s0f0np0 --permanent)
[root@e ~]# firewall-cmd --reload
[root@e ~]# firewall-cmd --get-active-zone
external
interfaces: enp3s0 <--- 「192.168.0.6」
trusted
interfaces: enp4s0 <--- 「192.168.1.1」
[root@e ~]#外側に曝されたnicを「external」にすると「masquerade」が有効になり、natpが利用可能になる
[root@e ~]# firewall-cmd --list-all --zone=external
external (active)
target: default
icmp-block-inversion: no
interfaces: enp3s0
sources:
services: ssh
ports:
protocols:
masquerade: yes
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@e ~]#各ゾーンの定義を理解すれば簡単なのかも
nfsを192.168.0.0/24側へ提供するには
[root@e ~]# firewall-cmd --add-service=nfs --zone=external --permanent
[root@e ~]# firewall-cmd --add-service=mountd --zone=external --permanent
[root@e ~]# firewall-cmd --add-service=rpc-bind --zone=external --permanent
[root@e ~]# firewall-cmd --reload
[root@e ~]# firewall-cmd --list-services --zone=external --permanent
ssh nfs mountd rpc-bind
[root@e ~]# firewall-cmd --list-all --zone=external
external (active)
target: default
icmp-block-inversion: no
interfaces: enp3s0
sources:
services: ssh nfs mountd rpc-bind
ports:
protocols:
masquerade: yes
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@e ~]#smb共有についても同様で
[root@e ~]# firewall-cmd --add-service=samba --zone=external --permanent
[root@e ~]# firewall-cmd --reloadとする
またルータへの5022アクセスを内部の 192.168.1.2:22 へ繋げるポーロフォワードは下記のようにする
[root@e ~]# firewall-cmd --zone=external --add-forward-port=port=5022:proto=tcp:toport=22:toaddr=192.168.1.2 --permanent
[root@e ~]# firewall-cmd --reload
[root@e ~]# firewall-cmd --list-all --zone=external
external (active)
target: default
icmp-block-inversion: no
interfaces: enp3s0
sources:
services: ssh nfs mountd rpc-bind
ports:
protocols:
masquerade: yes
forward-ports:
port=5022:proto=tcp:toport=22:toaddr=192.168.1.2
source-ports:
icmp-blocks:
rich rules:
[root@e ~]#ルータ内に仮想マシンを立てて「内部lan(trusted)」の機能を充実させようと思った

2枚目nicをbridgeに加えておけば大丈夫みたい

このときのip routeは下記のようになる
[root@e ~]# ip route
default via 192.168.0.1 dev enp3s0 proto static metric 100
192.168.0.0/24 dev enp3s0 proto kernel scope link src 192.168.0.6 metric 100
192.168.1.0/24 dev br0 proto kernel scope link src 192.168.1.1 metric 425
[root@e ~]#そして、NATPにするには nmcli コマンドを用いて br0 を「trusted」に移すして下記の様にする
[root@e ~]# firewall-cmd --get-active-zone
external
interfaces: enp3s0
trusted
interfaces: enp4s0 br0
[root@e ~]#仮想マシンの作成はlibvirt/仮想マシン作成に倣うが下記コマンドで実施
virt-install --connect qemu:///system --virt-type kvm --machine=pc \
--name ad --ram 1024 --cpu host --vcpus=1 --description "テストAD" --os-type linux \
--os-variant rhel7 --boot cdrom,hd,menu=on \
--disk path=/opt/kvm/HDD.qcow2.img,format=qcow2,bus=virtio,cache=writeback \
--cdrom /export/CentOS-7-x86_64-DVD-1611.iso --network bridge=br0,model=virtio \
--graphics vnc,port=5900,listen=0.0.0.0,keymap=jaすると、仮想的なnic(vnet0)が発生するが、これはbr0に所属のため「192.168.1.0/24」に属する
また「firewall-cmd --get-active-zone」コマンドには表示されない
[root@e ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.d05099c2a0ec yes enp4s0
vnet0
[root@e ~]# ip addr show master br0
7: enp4s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq master br0 state DOWN qlen 1000
link/ether d0:50:99:c2:a0:ec brd ff:ff:ff:ff:ff:ff
11: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN qlen 1000
link/ether fe:54:00:a8:8c:d1 brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fea8:8cd1/64 scope link
valid_lft forever preferred_lft forever
[root@e ~]# firewall-cmd --get-active-zone
external
interfaces: enp3s0
trusted
interfaces: enp4s0 br0
[root@e ~]#恐らく内部マシンで接続要求があったマシンの名前解決(DNS)が出来ていないからかと
[root@localhost ~]# vi /etc/ssh/sshd_config
:
UseDNS no
:
[root@localhost ~]# systemctl restart sshdで回避されるかと