업데이트: 솔루션이 작동하지 않습니다

업데이트: 솔루션이 작동하지 않습니다

기본적으로 INPUT, OUTPUT 및 FORWARD 규칙서의 모든 내용을 삭제하도록 iptables를 설정했습니다. 하지만 난 필요해포트 80을 통한 연결 허용(HTTP) 및포트 53에서 들어오는 모든 TCP/UDP 요청(DNS). 나는 다음과 같은 설정을 가지고 있습니다 :

Chain INPUT (policy DROP)
target      prot opt source            destination 
ACCEPT      tcp  --  anywhere          anywhere           tcp dpt:http
ACCEPT      udp  --  anywhere          anywhere           udp dpt:http  
ACCEPT      udp  --  anywhere          anywhere           udp dpt:domain
ACCEPT      tcp  --  anywhere          anywhere           tcp dpt:domain

Chain FORWARD (policy DROP)
target      prot opt source            destination 

Chain OUTPUT (policy DROP)
target      prot opt source            destination 
ACCEPT      udp  --  anywhere          anywhere           udp dpt:http
ACCEPT      tcp  --  anywhere          anywhere           tcp dpt:http  
ACCEPT      tcp  --  anywhere          anywhere           tcp dpt:domain
ACCEPT      udp  --  anywhere          anywhere           udp dpt:domain

그러나 를 실행하려고 하면 sudo apt-get install apache2패키지를 찾았지만 실제로 패키지를 다운로드하는 동안 멈춥니다. 내 연구에 따르면 apt-get은 대부분의 경우 작동하기 위해 HTTP 및 DNS 포트만 필요합니다.내가 뭐 놓친 거 없니?참고하려고 합니다이 게시물그러나 아무 소용이 없습니다.

Err:1 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libapr1 amd64 1.5.2-3
  Temporary failure resolving ‘us.archive.ubuntu.com’
Err:2 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libaprutil1 amd64 1.5.4-1build1
  Temporary failure resolving ‘us.archive.ubuntu.com’
0% [Connecting to us.archive.ubuntu.com]

시스템 메시지:
대리점 번호: 우분투
설명하다: 우분투 16.04.3 LTS
풀어 주다: 16.04
코드 네임: 셰니에


업데이트: 솔루션이 작동하지 않습니다

나는 팔로우한다도마성공하지 못한 채 아래에 다시 답변했습니다. apt-get위의 예와 같이 여전히 다운로드(예: apache2)가 중단되었습니다(즉, 변경 사항 없음). 내가 사용하려는 새로운 iptables는 다음과 같습니다.

Chain INPUT (policy DROP)
target      prot opt source            destination 
ACCEPT      all  --  anywhere          anywhere           state RELATED,ESTABLISHED

Chain FORWARD (policy DROP)
target      prot opt source            destination 

Chain OUTPUT (policy DROP)
target      prot opt source            destination 
ACCEPT      tcp  --  anywhere          anywhere           tcp dpt:http state NEW,RELATED,ESTABLISHED
ACCEPT      tcp  --  anywhere          anywhere           tcp dpt:domain state NEW,RELATED,ESTABLISHED
ACCEPT      udp  --  anywhere          anywhere           udp dpt:domain state NEW,RELATED,ESTABLISHED

룰북에서 버전을 출력해 보았습니다예, 아니오상태 메시지가 실패했습니다.

답변1

왜 53과 80에서 INPUT을 켜야 하는지는 모르겠지만 이것이 DNS와 HTTP로부터 응답을 받기 위한 것이라면 그것은 잘못된 것입니다. 이는 다음 줄을 사용하여 수행됩니다.

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 

(에서와 같이이 답변당신이 언급한 게시물로요. )

답변2

테스트 시스템을 통해 이에 대한 세부 사항을 파헤쳐봤습니다.

iptables다음 규칙 세트를 올바르게 구성 하고 apt-get올바르게 아웃바운드할 수 있습니다.

Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED

Chain FORWARD (policy DROP)
target     prot opt source               destination         

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80 state NEW,RELATED,ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:53 state NEW,RELATED,ESTABLISHED
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:53 state NEW,RELATED,ESTABLISHED

이는 위에서 언급한 최신 구성을 반영합니다. 문제가 잘 작동 할 수 있고 apt-get, DNS 쿼리도 문제 없이 수행할 수 있습니다.

그러나 시스템이 호스트 이름을 IP 주소로 확인하는 데 문제가 있을 수 있으며 확인 오류가 발생할 수 있다는 점에 유의하는 것이 중요합니다.

/etc/resolv.conf구성이 올바르고 최소한 다음이 포함되어 있는지 확인하세요 .

nameserver 8.8.8.8
nameserver 8.8.4.4

/etc/resolv.conf이러한 방식으로 설정하고 귀하와 동일한 규칙 세트를 사용 하면 iptables인터넷 연결 시스템은 물론 내부 네트워크에서 인터넷에 연결할 수 있는 자체 LAN 서브넷에 액세스하고 올바른 DNS 확인을 얻는 데 아무런 문제가 없습니다.

/etc/resolv.conf나에게는 설정이 올바르지 않고 구성이 잘못되어 시스템이 DNS를 올바르게 구성하지 못하는 것과 비슷합니다 .

답변3

안녕하세요 여러분, 이 문제에 대해 마음이 아프고 user147505의 답변을 100번 검색한 후 마침내 이것이 작동하지 않는 이유를 알아냈습니다. 이전 설정은 다음과 같습니다.-

root@myserver:~# iptables -L --line-numbers
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3652
2    ACCEPT     udp  --  anywhere             anywhere             udp dpt:51234
3    DROP       icmp --  anywhere             anywhere
4    DROP       all  --  anywhere             anywhere
5    ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     all  --  anywhere             anywhere
2    ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

보시다시피 위의 " " 규칙은 iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT모든 트래픽 규칙 "iptables -A INPUT -j DROP"을 제거한 후 추가되었습니다. 이것이 apt update작동하지 않았기 때문입니다.

그래서 결국 제가 한 일은 그것들을 아래와 같이 바꾸는 것뿐이었고 모든 것이 놀랍게 작동했습니다.

num  target     prot opt source               destination
1    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3652
2    ACCEPT     udp  --  anywhere             anywhere             udp dpt:51234
3    DROP       icmp --  anywhere             anywhere
4    ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
5    DROP       all  --  anywhere             anywhere

나는 iptables에 대해 뭔가를 배웠고 앞으로 이 jaba Huba를 이해하기 위한 과정을 수강하고 싶습니다.

관련 정보