kvm / qemu로 일부 Linux 게스트를 가상화하기 위해 개발 서버에 최소 CentOS 7 버전을 설치했습니다.
firewalld
설치하는 대신 iptables를 사용 하려면 다음 iptables-service
을 수행하십시오.
systemctl stop firewalld
systemctl mask firewalld
systemctl enable iptables
systemctl start iptables
편집하여 SELinux를 사용할 수 없습니다 /etc/sysconfig/selinux
.
iptables에 대한 나의 규칙은 다음과 같습니다.
iptables -Z
iptables -F
iptables -X
iptables -t nat -Z
iptables -t nat -F
iptables -t nat -X
iptables -t nat -A POSTROUTING -o enp6s0 -j MASQUERADE
iptables -A FORWARD -i enp6s0 -o virbr0 -j ACCEPT
이제 다음 명령으로 설정을 저장합니다.
iptables-save > /etc/sysconfig/iptables
내 iptables-file
외모 :
# Generated by iptables-save v1.4.21 on Thu Aug 20 10:46:40 2015
*mangle
:PREROUTING ACCEPT [16736:10889078]
:INPUT ACCEPT [1063:106860]
:FORWARD ACCEPT [15679:10784186]
:OUTPUT ACCEPT [570:71275]
:POSTROUTING ACCEPT [15728:10809742]
-A POSTROUTING -o virbr0 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill
COMMIT
# Completed on Thu Aug 20 10:46:40 2015
# Generated by iptables-save v1.4.21 on Thu Aug 20 10:46:40 2015
*filter
:INPUT ACCEPT [868:81772]
:FORWARD ACCEPT [8328:7311589]
:OUTPUT ACCEPT [233:32016]
-A FORWARD -i enp6s0 -o virbr0 -j ACCEPT
COMMIT
# Completed on Thu Aug 20 10:46:40 2015
# Generated by iptables-save v1.4.21 on Thu Aug 20 10:46:40 2015
*nat
:PREROUTING ACCEPT [1308:86998]
:INPUT ACCEPT [77:12475]
:OUTPUT ACCEPT [1:72]
:POSTROUTING ACCEPT [1228:74319]
-A POSTROUTING -o enp6s0 -j MASQUERADE
COMMIT
# Completed on Thu Aug 20 10:46:40 2015
내 규칙이 올바른지 확인하는 빠른 점검 :
[root@dev1 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
그러나 서버를 재부팅 한 후 iptables 규칙은 다음과 같습니다.
[root@dev1 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:domain
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
ACCEPT udp -- anywhere anywhere udp dpt:bootps
ACCEPT tcp -- anywhere anywhere tcp dpt:bootps
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere 10.0.1.0/24 ctstate RELATED,ESTABLISHED
ACCEPT all -- 10.0.1.0/24 anywhere
ACCEPT all -- anywhere anywhere
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:bootpc
다른 규칙의 출처를 이해하지 못합니다.
호출 할 때 iptables-restore -c /etc/sysconfig/iptables
예상 규칙이 표시됩니다.
저장된 규칙이 부팅시로드되지 않거나 "기본"규칙이 플러시되지 않는 것 같습니다.
여기서 문제는 무엇입니까 ??? 나는 천천히 회색 머리카락을 얻고 있습니다 ...
빠른 답변 감사합니다 :)
위에서 언급했듯이 iptables-services는 나에 의해 설치되었습니다.
[root@dev1 ~]# rpm -aq iptables-services
iptables-services-1.4.21-13.el7.x86_64
사용하는 systemctl enable iptables.service
대신 서비스를 사용 systemctl enable iptables
하면 동일한 서비스 파일이 연결되어 있기 때문에 아무런 차이가 없습니다.
[root@dev1 ~]# systemctl disable iptables
rm '/etc/systemd/system/basic.target.wants/iptables.service'
[root@dev1 ~]# systemctl enable iptables.service
ln -s '/usr/lib/systemd/system/iptables.service' '/etc/systemd/system/basic.target.wants/iptables.service'
이것은 호출 후 iptables 파일의 내용입니다
/usr/libexec/iptables/iptables.init save
[root@develcluster1 ~]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.21 on Fri Aug 21 14:34:04 2015
*nat
:PREROUTING ACCEPT [351490:22546787]
:INPUT ACCEPT [15751:2400243]
:OUTPUT ACCEPT [324:21186]
:POSTROUTING ACCEPT [304860:18293418]
-A POSTROUTING -o enp6s0 -j MASQUERADE
COMMIT
# Completed on Fri Aug 21 14:34:04 2015
# Generated by iptables-save v1.4.21 on Fri Aug 21 14:34:04 2015
*filter
:INPUT ACCEPT [505048:69178501]
:FORWARD ACCEPT [55815086:22035726185]
:OUTPUT ACCEPT [325986:56595531]
-A FORWARD -i enp6s0 -o virbr0 -j ACCEPT
COMMIT
# Completed on Fri Aug 21 14:34:04 2015
# Generated by iptables-save v1.4.21 on Fri Aug 21 14:34:04 2015
*mangle
:PREROUTING ACCEPT [109215513:66867793592]
:INPUT ACCEPT [505243:69203589]
:FORWARD ACCEPT [108710264:66798590873]
:OUTPUT ACCEPT [326323:56634790]
:POSTROUTING ACCEPT [109036066:66855179944]
-A POSTROUTING -o virbr0 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill
COMMIT
# Completed on Fri Aug 21 14:34:04 2015
재부팅 후 iptables -L
저장된 규칙을 표시하지 않는 호출 :
[root@dev1 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:domain
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
ACCEPT udp -- anywhere anywhere udp dpt:bootps
ACCEPT tcp -- anywhere anywhere tcp dpt:bootps
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere 10.0.1.0/24 ctstate RELATED,ESTABLISHED
ACCEPT all -- 10.0.1.0/24 anywhere
ACCEPT all -- anywhere anywhere
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:bootpc
어쩌면 나는 근본적으로 잘못된 일을하고있을 것입니다. 그러나 내가 읽은 모든 스레드는 동일한 방식으로 작동하며 작동해야합니다.
더 자세한 정보가 필요하면 알려주십시오.
한편, 나는 재부팅 할 때마다 호출 해야하는 작은 스크립트를 호출하여 나를 도왔습니다.
#!/bin/sh
iptables -Z
iptables -F
iptables -X
iptables -t nat -Z
iptables -t nat -F
iptables -t nat -X
iptables -t nat -A POSTROUTING -o enp6s0 -j MASQUERADE
iptables -A FORWARD -i enp6s0 -o virbr0 -j ACCEPT
iptables --flush
iptables-restore -c /etc/sysconfig/iptables
섹시하지는 않지만 지금까지 작동합니다. 그러나 최종 해결책은 될 수 없습니다.
service stop|mask firewalld
)