20160729 방화벽
4 | iptables 간단한 실습 |
(기본적인 사용법)
# iptables -L /* -L : list */
# iptables -L -v
# iptables -F /* -F : Flush */
# iptables -F INPUT
# iptables -P INPUT DROP /* -P : Policy */
# iptables -P INPUT ACCEPT
# iptables -A INPUT -p tcp --dport 23 -j ACCEPT
# service iptables save
# service iptables start
# service iptables stop
# service iptables restart
# service iptables status
# chkconfig --list iptables
# chkconfig iptables on
파일 이름: /etc/sysconfig/iptables
[EX1] 기본적인 사용법
(전제 조건)
■ 방화벽 서버에서는 다음과 같은 명령어가 수행되어 있는 것으로 가정한다.
# tail -f /var/log/messages /var/log/secure
■ nmap 설치가 되어 있어야 한다.
# nmap localhost (# vi /etc/resolv.conf ; yum -y install nmap)
# nmap -V
■ tcp_wrappers 기능은 사용하지 않는다.
# cat /etc/hosts.allow
# cat /etc/hosts.deny
① 현재 iptables 확인
# iptables -h
iptables v1.3.5
Usage: iptables -[AD] chain rule-specification [options] iptables -[RI] chain rulenum rule-specification [options] iptables -D chain rulenum [options] iptables -[LFZ] [chain] [options] iptables -[NX] chain iptables -E old-chain-name new-chain-name iptables -P chain target [options] iptables -h (print this help information)
Commands: Either long or short options are allowed. --append -A chain Append to chain --delete -D chain Delete matching rule from chain --delete -D chain rulenum Delete rule rulenum (1 = first) from chain --insert -I chain [rulenum] Insert in chain as rulenum (default 1=first) --replace -R chain rulenum Replace rule rulenum (1 = first) in chain --list -L [chain] List the rules in a chain or all chains --flush -F [chain] Delete all rules in chain or all chains --zero -Z [chain] Zero counters in chain or all chains --new -N chain Create a new user-defined chain --delete-chain -X [chain] Delete a user-defined chain --policy -P chain target Change policy on chain to target --rename-chain -E old-chain new-chain Change chain name, (moving any references) Options: --proto -p [!] proto protocol: by number or name, eg. `tcp' --source -s [!] address[/mask] source specification --destination -d [!] address[/mask] destination specification --in-interface -i [!] input name[+] network interface name ([+] for wildcard) --jump -j target target for rule (may load target extension) --goto -g chain jump to chain with no return --match -m match extended match (may load extension) --numeric -n numeric output of addresses and ports --out-interface -o [!] output name[+] network interface name ([+] for wildcard) --table -t table table to manipulate (default: `filter') --verbose -v verbose mode --line-numbers print line numbers when listing --exact -x expand numbers (display exact values) [!] --fragment -f match second or further fragments only --modprobe=<command> try to insert modules using this command --set-counters PKTS BYTES set the counter during insert/append [!] --version -V print package version. |
# uname -a
Linux linux249.example.com 2.6.18-164.el5 #1 SMP Thu Sep 3 03:33:56 EDT 2009 i686 athlon i386 GNU/Linux |
# iptables -V
iptables v1.3.5 |
# iptables -L (# iptables -L -t filter)
Chain INPUT (policy ACCEPT) target prot opt source destination
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination |
② INPUT 체인에 대한 기본 정책 설정
# iptables -P INPUT DROP
# iptables -L
Chain INPUT (policy DROP) target prot opt source destination
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination |
③ INPUT 체인에 규칙(Rules) 추가
# iptables -A INPUT -p tcp --dport 23 -j ACCEPT
# iptables -L (# iptables -vL)
Chain INPUT (policy DROP) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:telnet
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination |
# service iptables status
Table: filter Chain INPUT (policy DROP) num target prot opt source destination 1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:23
Chain FORWARD (policy ACCEPT) num target prot opt source destination
Chain OUTPUT (policy ACCEPT) num target prot opt source destination |
④ /etc/sysconfig/iptable 파일에 저장
# ls -l /etc/sysconfig/iptables
ls: /etc/sysconfig/iptables: No such file or directory |
# service iptables save
Saving firewall rules to /etc/sysconfig/iptables: [ OK ] |
-> MEM 안에 들어 있는 iptables(firewall) 설정을 파일(/etc/sysconfig/iptables)에 저장한다.
# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.3.5 on Tue Mar 30 02:44:34 2010 *filter :INPUT DROP [2:470] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [6522:278819] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT COMMIT # Completed on Tue Mar 30 02:44:34 2010 |
-> 이 파일에 저장이 되면 부팅시에도 이 설정이 다시 올라온다.
-> 부팅시에
# chkconfig iptables on
# cat /etc/sysconfig/iptables
⑤ iptables Flush
# iptables -F (# iptables -F INPUT)
#
-> MEM 안의 Firwall 설정/룰(rules)를 flush 시킨다.
-> 파일(/etc/sysconfig/iptables)의 내용을 flush 시키는 것은 아니다.
# iptables -L
Chain INPUT (policy DROP) target prot opt source destination
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination |
⑥ iptables 현재 start
# service iptables start
Flushing firewall rules: [ OK ] Setting chains to policy ACCEPT: filter [ OK ] Unloading iptables modules: [ OK ] Applying iptables firewall rules: [ OK ] Loading additional iptables modules: ip_conntrack_netbios_n[ OK ] |
-> 서비스가 start 되면 설정 파일(/etc/sysconfig/iptables)을 다시 읽어 메모리상으로 로딩한다.
# iptables -L
Chain INPUT (policy DROP) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:telnet
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination |
⑦ iptables 서비스 현재 stop
# service iptables stop
Flushing firewall rules: [ OK ] Setting chains to policy ACCEPT: filter [ OK ] Unloading iptables modules: [ OK ] |
-> /etc/sysconfig/iptables 파일이 삭제된것은 아니다.
-> 따라서 부팅이 되면 서비스가 다시 올라온다.
# iptables -L
Chain INPUT (policy ACCEPT) target prot opt source destination
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination |
# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.3.5 on Fri Aug 26 12:18:49 2011 *filter :INPUT DROP [979:102009] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [97:14696] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT COMMIT # Completed on Fri Aug 26 12:18:49 2011 |
# chkconfig --list | grep iptables
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off |
# chkconfig iptables off
# chkconfig --list | grep iptables
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off |
-> 부팅시에 iptables OFF
# chkconfig iptables on
# chkconfig --list | grep iptables
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off |
■ 방화벽 서비스 관리
(현재) # service iptables start/stop
(부팅) # chkconfig iptables on/off
■ 작업하는 방법
(전제조건) /etc/sysconfig/iptables 파일이 존재하고 룰(rules)이 존재한다.
# iptables -A ......
# service iptables save
or
# vi /etc/sysconfig/iptables
# service iptables reload
5 | iptables 방화벽 정책 실습 |
방화벽 정책을 세워보자.
/etc/sysconfig/iptables 파일을 사용하지 않고 따로 스크립트(EX: /root/bin/iptables.sh) 를 만들어서 사용하였다.
iptables 설정은 (ㄱ) 네트워크(네트워크 방화벽)쪽에서 설정할수 있거나 (ㄴ) 서버(서버 방화벽)쪽에서 설정할 수 있거나 (ㄷ) 일반 PC(개인 방화벽)에서 설정할 수 있다.
이 문서에서는 서버 방화벽 형태의 룰(rules)에 대한 부분만을 다룬다.
|
[그림] 실습 구성도
서버 엔지니어가 관리하는 서버가 존재한다고 본다면, 그 서버는 여러가지 접근 제어 서비스(Access Control Service)를 받는 경우가 많다. 예를 들어 이런 서비스는 방화벽, IPS(침입차단시스템), IDS(침입탐지시스템), 스크리닝 라우터, 라우터의 ACL등이다. 하지만 이런 서비스는 외부에서 내부를 보호하기 위한 목적으로 주로 사용하고 있다. 내부에 있는 서버가 다른 내부의 서버에 대한 접근 제어에는 취약한 점이 많다. 이런경우 내부의 악의적인 사용자들에게 서버들이 노출되기 때문에 위험하다. 이런경우 서버 방화벽을 켜고 사용하게 되면 악의적인 내부 사용자들을 쉽게 방어할 수 있게 된 다. 특정한 서버와만 통신할수 있도록 설정하는것이다.
서버 방화벽 구성(Server Firewall Configuration)
------------------------------------------------
■ 실습 준비
■ 모든 서비스 차단
■ telnet 서비스 허용
■ rlogin 서비스 허용
■ SSH 서비스 허용
■ ICMP 서비스 허용
■ WEB 서비스 허용
■ NFS 서비스 허용
■ NTP 서비스 허용
■ DNS 서비스 허용
■ FTP 서비스 허용
■ MAIL, POP3, IMAP 서비스 허용
------------------------------------------------
(가정) 다음 사항을 가정한다.
CentOS 5.4/CentOS 5.8/CentOS 5.9/CentOS 5.10/CentOS 5.11 환경에서 테스트 한다.
모든 서버에 최신의 패치(# yum -y update)가 적용되어 있는 것으로 가정한다.# yum check-update (check-update Check for available package updates)# yum -y update -> 커널 업데이트가 들어 있는 경우(# yum check-update | grep kernel)# reboot
[EX1] 실습 준비
Firewall(iptables) ■ Linux(KaliLinux) <----------> ■ Linux(firwall) <----------> ■ Linux(linux200) 192.168.10.50 192.168.10.100 192.168.20.100 192.168.20.200 ■ Windows(win2008) 192.168.20.201 |
[그림] 실습 환경
방화벽 서버와 통신 가능 확인
모든 서버에 nmap(Port Scanning) 프로그램 설치
(192.168.20.200) linux200
서버가 통신 가능한 상태인지 ping 명령어를 통해 확인
대표적인 서비스 몇가지, telnet, ftp, 서비스가 서버와 통신이 가능한지 확인한다.
① 서버와 통신 가능 확인(ping)
# ping -c 2 192.168.20.100
PING 192.168.20.100 (192.168.20.100) 56(84) bytes of data. 64 bytes from 192.168.20.100: icmp_seq=1 ttl=64 time=0.951 ms 64 bytes from 192.168.20.100: icmp_seq=2 ttl=64 time=0.532 ms
--- 192.168.20.100 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms rtt min/avg/max/mdev = 0.532/0.741/0.951/0.211 ms |
② 서버와 통신 가능 확인(telnet)
[참고] 필요하면 설정
(firewall) 192.168.20.100
# chkconfig krb5-telnet on
# service xinetd restart
# for i in `seq 1 11`
do
echo "pts/$i" >> /etc/securetty
done
■ (linux200 --- telnet ---> firewall)
# telnet 192.168.20.100
Trying 192.168.10.2XX... Connected to 192.168.10.2XX (192.168.10.2XX). Escape character is '^]'.
linux2XX (Linux release 2.6.18-164.15.1.el5 #1 SMP Wed Mar 17 11:37:14 EDT 2010) (3)
login: root Password: (soldesk1.) Last login: Tue Mar 30 02:24:00 from 192.168.10.1XX # <CTRL + D> |
③ 서버와 통신 가능 확인(ftp)
[참고] 필요하면 설정
(firewall) 192.168.20.100
# chkconfig vsftpd on
# service vsftpd restart
# sed -i 's/^root/#root/' /etc/vsftpd/ftpusers
# sed -i 's/^root/#root/' /etc/vsftpd/user_list
■ (linux200 --- ftp ---> firewall)
# ftp 192.168.20.100
Connected to 192.168.20.100. 220 (vsFTPd 2.0.5) 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (192.168.20.100:root): root 331 Please specify the password. Password: (root 사용자 암호 입력) 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> quit 221 Goodbye. |
④ 서버의 열린 포트 확인
[참고] 필요하면 명령어 수행
# vi /etc/resolv.conf
nameserver 168.126.63.1
nameserver 172.16.9.2XX
# yum -y install nmap
■ (linux200 --- nmap ---> firewall)
# nmap 192.168.20.100
Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2014-12-09 16:57 KST Interesting ports on nic2 (192.168.20.100): Not shown: 1674 closed ports PORT STATE SERVICE 21/tcp open ftp 22/tcp open ssh 23/tcp open telnet 37/tcp open time 111/tcp open rpcbind 643/tcp open unknown MAC Address: 00:0C:29:A2:83:8F (VMware)
Nmap finished: 1 IP address (1 host up) scanned in 0.230 seconds |
[참고] 포트번호의 정의(IANA)
- http://www.iana.org/assignments/port-numbers
- /etc/services 파일
[EX2] 모든 서비스 차단
(192.168.20.100) Firewall
(선수작업) 별도의 스크립트를 사용하기 위해서 iptables 서비스는 off 시킨다.
# chkconfig iptables off
# chkconfig --list iptables
# mkdir -p /root/bin
# vi /root/bin/iptables.sh
#!/bin/bash
iptables -F -t filter iptables -F -t nat
# # (1) Local ACCEPT # iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# # (2) Policy #
# # (3) All DROP # iptables -P INPUT DROP |
Statefull TrackingUsing stateful rules reduces rule set complexity and increses security
-m state --state ESTABLEISHED,RELATED
state This module, when combined with connection tracking, allows access to the connection tracking state for this packet.
--state state Where state is a comma separated list of the connection states to match. Possible states are INVALID meaning that the packet could not be identified for some reason which includes running out of memory and ICMP errors which don't correspond to any known connection, ESTABLISHED meaning that the packet is associated with a connection which has seen packets in both directions, NEW meaning that the packet has started a new connection, or otherwise associated with a connection which has not seen packets in both directions, and RELATED meaning that the packet is starting a new con- nection, but is associated with an existing connection, such as an FTP data transfer, or an ICMP error. |
# chmod 755 /root/bin/iptables.sh
# /root/bin/iptables.sh
# iptables -L
Chain INPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination |
(192.168.20.200) linux200
■ (linux200 --- ping ---> firewall)
# time ping -c 1 192.168.20.100
PING 192.168.20.100 (192.168.20.100) 56(84) bytes of data.
--- 192.168.20.100 ping statistics --- 1 packets transmitted, 0 received, 100% packet loss, time 0ms
real 0m10.044s user 0m0.005s sys 0m0.032s |
■ (linux200 --- nmap ---> firewall)
# time nmap 192.168.20.100
Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2014-12-09 17:24 KST All 1680 scanned ports on nic2 (192.168.20.100) are filtered MAC Address: 00:0C:29:A2:83:8F (VMware)
Nmap finished: 1 IP address (1 host up) scanned in 35.242 seconds
real 0m35.251s user 0m0.077s sys 0m0.006s |
[EX3] telnet 서비스 제어
|
(192.168.20.100) Firewall
telnet 서비스를 open 하기 위한 설정을 한다.
tenlet 서비스용 서버 포트는 23번(TCP)를 사용하고 있다.
telnet 서비스는 암호화 방식을 택하지 않고 평문 형태의 패킷으로 통신하게 된다. 따라서 telnet 서버스를 반드시 사용해야 한다면 특정한 PC만 서버에 접속할 수 있도록 설정해야 한다.
# vi /root/bin/iptables.sh
#!/bin/ksh
iptables -F iptables -F -t nat
# # (1) Local ACCEPT # iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# # (2) Policy # iptables -A INPUT -m state --state NEW -p tcp -s 192.168.20.200 -d 192.168.20.100 --dport 23 -j ACCEPT
# # (3) All DROP # iptables -P INPUT DROP |
# /root/bin/iptables.sh
# iptables -L (# service iptables status)
Chain INPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- 192.168.20.200 nic2 state NEW tcp dpt:telnet
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination |
(192.168.20.200) linux200
# telnet 192.168.20.100
Trying 192.168.20.100... Connected to nic2 (192.168.20.100). Escape character is '^]'.
firewall.example.com (Linux release 2.6.18-371.12.1.el5 #1 SMP Wed Sep 3 16:22:56 EDT 2014) (1)
login: root Password: (root 사용자의 암호 입력) Last login: Tue Mar 30 03:30:11 from 192.168.10.1XX You have new mail. |
# exit
#
# time nmap 192.168.20.100
Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2014-12-09 17:31 KST Interesting ports on nic2 (192.168.20.100): Not shown: 1679 filtered ports PORT STATE SERVICE 23/tcp open telnet MAC Address: 00:0C:29:A2:83:8F (VMware)
Nmap finished: 1 IP address (1 host up) scanned in 22.043 seconds
real 0m22.051s user 0m0.076s sys 0m0.013s |
[참고] 다른 호스트 쪽에서 telnet 서비스를 192.168.10.2XX 서버쪽으로 테스트해 본다.
(KaliLinux) 192.168.10.50
# telnet 192.168.10.100
# nmap 192.168.10.100
(Windows2008) 192.168.20.201
Putty 사용해서 telnet 해 본다.(192.168.20.201 -> 192.168.20.100)
필요하면 Windows nmap으로 확인 해 본다.
[EX4] SSH 서비스 제어
|
192.168.20.0/24 네트워크에서 ssh 명령어 접속을 할 수 있도록 설정한다.
ssh 서비스는 데이터를 전송할 때 암호화 하므로 서버와 같은 네트워크를 사용하고 있는 경우 모두에게 서비스가 가능하도록 설정한다.
SSH 서비스용 서버 포트는 22번(ssh, sftp, scp, TCP)을 사용한다.
(192.168.20.100) Firewall
# vi /root/bin/iptables.sh
#!/bin/ksh
iptables -F iptables -F -t nat
# # (1) Local ACCEPT # iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# # (2) Policy # iptables -A INPUT -m state --state NEW -p tcp -s 192.168.20.200 -d 192.168.20.100 --dport 23 -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp -s 192.168.20.0/24 -d 192.168.20.100 --dport 22 -j ACCEPT
# # (3) All DROP # iptables -P INPUT DROP |
[참고] 필요하면 명령어 수행
# alias a='vi /root/bin/iptables.sh'
# alias b='/root/bin/iptables.sh'
# alias c='iptables -L'
# /root/bin/iptables.sh
# iptables -L (# service iptables status)
Chain INPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- 192.168.20.200 nic2 state NEW tcp dpt:telnet ACCEPT tcp -- 192.168.20.0/24 nic2 state NEW tcp dpt:ssh
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination |
(192.168.20.200) linux200
# ssh 192.168.20.100
The authenticity of host '192.168.20.100 (192.168.20.100)' can't be established. RSA key fingerprint is c6:d1:9a:14:84:6c:1b:df:4d:b0:3b:53:b5:1f:7a:73. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.20.100' (RSA) to the list of known hosts. root@192.168.20.100's password: (soldesk1.) Last login: Tue Dec 9 17:30:05 2014 from 192.168.20.200 |
# exit
#
# nmap 192.168.20.100
Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2014-12-09 17:42 KST Interesting ports on nic2 (192.168.20.100): Not shown: 1678 filtered ports PORT STATE SERVICE 22/tcp open ssh 23/tcp open telnet MAC Address: 00:0C:29:A2:83:8F (VMware)
Nmap finished: 1 IP address (1 host up) scanned in 21.212 seconds |
[참고] 다른 호스트 쪽에서 ssh 서비스를 linux2XX 서버쪽으로 테스트해 본다.
(KaliLinux)
# ssh 192.168.10.100
# nmap 192.168.10.100
(Windows2008)
Putty 사용해서 ssh 해 본다.(192.168.20.201 -> 192.168.20.100)
필요하면 Windows nmap으로 확인 해 본다.
[EX5] ICMP 서비스 허용/차단
|
(192.168.20.100) Firewall
# vi /root/bin/iptables.sh
#!/bin/ksh
iptables -F iptables -F -t nat
# # (1) Local ACCEPT # iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# # (2) Policy # iptables -A INPUT -m state --state NEW -p tcp -s 192.168.20.200 -d 192.168.20.100 --dport 23 -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp -s 192.168.20.0/24 -d 192.168.20.100 --dport 22 -j ACCEPT iptables -A OUTPUT -p icmp --icmp-type echo-request -s 192.168.20.100 -d 0/0 -j ACCEPT iptables -A INPUT -p icmp --icmp-type echo-reply -s 0/0 -d 192.168.20.100 -j ACCEPT iptables -A INPUT -p icmp --icmp-type destination-unreachable -s 0/0 -d 192.168.20.100 -j ACCEPT
# # (3) All DROP # iptables -P INPUT DROP |
[참고] iptables -p icmp -h |
# iptables -p icmp –h iptables v1.3.5
..... (중략) .....
Valid ICMP Types: any echo-reply (pong) destination-unreachable network-unreachable host-unreachable protocol-unreachable port-unreachable fragmentation-needed source-route-failed network-unknown host-unknown network-prohibited host-prohibited TOS-network-unreachable TOS-host-unreachable communication-prohibited host-precedence-violation precedence-cutoff source-quench redirect network-redirect host-redirect TOS-network-redirect TOS-host-redirect echo-request (ping) router-advertisement router-solicitation time-exceeded (ttl-exceeded) ttl-zero-during-transit ttl-zero-during-reassembly parameter-problem ip-header-bad required-option-missing timestamp-request timestamp-reply address-mask-request address-mask-reply |
# /root/bin/iptables.sh
# iptables -L (# service iptables status)
Chain INPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- 192.168.20.200 nic2 state NEW tcp dpt:telnet ACCEPT tcp -- 192.168.20.0/24 nic2 state NEW tcp dpt:ssh ACCEPT icmp -- nic2 anywhere icmp echo-request ACCEPT icmp -- anywhere nic2 icmp echo-reply ACCEPT icmp -- anywhere nic2 icmp destination-unreachable
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination |
# ping -c 2 192.168.20.200
PING 192.168.10.1XX (192.168.10.1XX) 56(84) bytes of data. 64 bytes from 192.168.10.1XX: icmp_seq=1 ttl=64 time=1.12 ms 64 bytes from 192.168.10.1XX: icmp_seq=2 ttl=64 time=1.03 ms
--- 192.168.10.1XX ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1523ms rtt min/avg/max/mdev = 1.030/1.077/1.125/0.057 ms |
(192.168.20.200) linux200
# ping -c 1 192.168.20.100
PING 192.168.10.2XX (192.168.10.2XX) 56(84) bytes of data.
--- 192.168.10.2XX ping statistics --- 1 packets transmitted, 0 received, 100% packet loss, time 0ms |
[EX6] WEB 서비스 허용
|
WEB(80, TCP)
(192.168.20.100) Firewall
# vi /root/bin/iptables.sh
..... (중략) ..... # # (2) Policy # iptables -A INPUT -m state --state NEW -p tcp -s 192.168.10.1XX -d 192.168.10.2XX --dport 23 -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp -s 192.168.10.0/24 -d 192.168.10.2XX --dport 22 -j ACCEPT iptables -A INPUT -p icmp --icmp-type echo-request -s 192.168.10.2XX -d 0/0 -j ACCEPT iptables -A INPUT -p icmp --icmp-type echo-reply -s 0/0 -d 192.168.10.2XX -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp -s 0/0 -d 192.168.20.100 --dport 80 -j ACCEPT ..... (중략) ..... |
# /root/bin/iptables.sh
# iptables -L (# service iptables status)
Chain INPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- 192.168.20.200 nic2 state NEW tcp dpt:telnet ACCEPT tcp -- 192.168.20.0/24 nic2 state NEW tcp dpt:ssh ACCEPT icmp -- nic2 anywhere icmp echo-request ACCEPT icmp -- anywhere nic2 icmp echo-reply ACCEPT icmp -- anywhere nic2 icmp destination-unreachable ACCEPT tcp -- anywhere nic2 state NEW tcp dpt:http
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination |
# rpm -qa | grep httpd
httpd-2.2.3-87.el5.centos httpd-manual-2.2.3-87.el5.centos system-config-httpd-1.3.3.3-1.el5 |
# cd /var/www/html
# vi index.html
<H1><CENTER> firewall.example.com </CENTER></H1> |
# service httpd restart
Stopping httpd: [ OK ] Starting httpd: [ OK ] |
(192.168.20.200) linux200
# lynx http://192.168.20.100/ (# firefox http://192.168.20.100)
-> 웹페이가 보여야 한다.
-> # telnet 192.168.20.100 80
GET
# nmap 192.168.20.100
Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2014-12-09 18:17 KST Interesting ports on nic2 (192.168.20.100): Not shown: 1677 filtered ports PORT STATE SERVICE 22/tcp open ssh 23/tcp open telnet 80/tcp open http MAC Address: 00:0C:29:A2:83:8F (VMware)
Nmap finished: 1 IP address (1 host up) scanned in 20.392 seconds |
[참고] 다른 호스트 쪽에서 ssh 서비스를 linux2XX 서버쪽으로 테스트해 본다.
(KaliLinux)
# telnet 192.168.10.100 80
GET
# nmap 192.168.10.100
(Windows2008)
c:> telnet 192.168.20.100 80
GET
필요하면 Windows nmap으로 확인 해 본다.
[EX8] NFS 서비스 허용
|
# rpcinfo -t linux2XX.example.com nfs
program 100003 version 2 ready and waiting
program 100003 version 3 ready and waiting
program 100003 version 4 ready and waiting
# rpcinfo -u linux2XX.example.com nfs
program 100003 version 2 ready and waiting
program 100003 version 3 ready and waiting
program 100003 version 4 ready and waiting
(1) NFSv2/NFSv3 서비스의 동작 원리
----- NFS Server ------ ----- NFS Client -----
rpc.mountd rpc.statd
rpc.nfsd rpc.lockd
rpc.rquotad
rpc.statd
rpc.lockd
# vi /etc/exports # mkdir /p
# exportfs -ar # mount.nfs4 SERVER:/share /p
(2) NFSv4 서비스의 동작 원리
[참고] NFSv4 서버/클라이언트 설정 방법
http://blog.laimbock.com/2009/05/21/nfsv4-on-centos-53-and-fedora-11/http://blog.laimbock.com/2009/05/21/nfsv4-on-centos-53-and-fedora-11/
(192.168.10.2XX) Firewall Server (linux2XX)
# vi /root/bin/iptables.sh
..... (중략) ..... # # (2) Policy # iptables -A INPUT -m state --state NEW -p tcp -s 192.168.10.1XX -d 192.168.10.2XX --dport 23 -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp -s 192.168.10.0/24 -d 192.168.10.2XX --dport 22 -j ACCEPT iptables -A INPUT -p icmp --icmp-type echo-request -s 192.168.10.2XX -d 0/0 -j ACCEPT iptables -A INPUT -p icmp --icmp-type echo-reply -s 0/0 -d 192.168.10.2XX -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp -s 0/0 -d 192.168.10.2XX --dport 80 -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp -s 192.168.10.1XX -d 192.168.10.2XX --dport 2049 -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp -s 192.168.10.1XX -d 192.168.10.2XX --dport 111 -j ACCEPT iptables -A INPUT -m state --state NEW -p udp -s 192.168.10.1XX -d 192.168.10.2XX --dport 111 -j ACCEPT ..... (중략) ..... |
-> rpcbind(111) 포트를 반드시 Open 필요는 없다.
-> NFSv4(nfsd) 서비스는 2049번 단일 포트를 사용하고, 단일 프로토콜 TCP를 사용한다.
# /root/bin/iptables.sh
# service iptables status (# iptables -L)
Table: filter Chain INPUT (policy DROP) num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 3 ACCEPT tcp -- 192.168.10.1XX 192.168.10.2XX state NEW tcp dpt:23 4 ACCEPT tcp -- 192.168.10.0/24 192.168.10.2XX state NEW tcp dpt:22 5 ACCEPT icmp -- 192.168.10.2XX 0.0.0.0/0 icmp type 8 6 ACCEPT icmp -- 0.0.0.0/0 192.168.10.2XX icmp type 0 7 ACCEPT tcp -- 0.0.0.0/0 192.168.10.2XX state NEW tcp dpt:80 8 ACCEPT tcp -- 192.168.10.1XX 192.168.10.2XX state NEW tcp dpt:2049 9 ACCEPT tcp -- 192.168.10.1XX 192.168.10.2XX state NEW tcp dpt:111 10 ACCEPT udp -- 192.168.10.1XX 192.168.10.2XX state NEW udp dpt:111
Chain FORWARD (policy ACCEPT) num target prot opt source destination
Chain OUTPUT (policy ACCEPT) num target prot opt source destination |
# vi /etc/exports
..... (중략) ..... /export/centos *(ro,no_root_squash) |
# service nfs restart
-> 출력 내용 생략
# exportfs -v
/export/centos <world>(ro,wdelay,no_root_squash,no_subtree_check,anonuid=65534,anongid=65534) |
(192.168.10.1XX) Client (linux1XX)
# mkdir –p /mnt/server
# mount 192.168.10.2XX:/export/centos /mnt/server
# df –h /mnt/server
# ls /mnt/server
# nmap -sT 192.168.10.2XX
Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2010-09-02 15:23 KST Interesting ports on 192.168.10.250: Not shown: 1676 filtered ports PORT STATE SERVICE 22/tcp open ssh 23/tcp open telnet 80/tcp open http 111/tcp open rpcbind 2049/tcp open nfs MAC Address: 00:0C:29:88:90:CB (VMware)
Nmap finished: 1 IP address (1 host up) scanned in 33.227 seconds |
-> 포트번호를 검색한다.
-> 원격 자원 마우트를 시도해 본다.
[참고] system-config-securitylevel 툴을 통해 설정한 내용(선택할 수 있는 모든 서비스 허용)
(TUI) # system-config-securitylevel-tui (# lokkit)
(GUI) # system-config-securitylevel
# iptables -F
# iptables -P INPUT ACCEPT (# service iptables stop)
# iptables -L
-> 특별한 설정이 없는 상태
# system-config-securitylevel &
--------------------------------------------------
Firewall: Enabled
Trusted services: [ V ] FTP
[ V ] Mail (SMTP)
[ V ] NFSv4
[ V ] SSH
[ V ] Samba
[ V ] Secure WWW (HTTPS)
[ V ] Telnet
[ V ] WWW (HTTP)
--------------------------------------------------
# iptables -L
Chain INPUT (policy ACCEPT) target prot opt source destination RH-Firewall-1-INPUT all -- anywhere anywhere
Chain FORWARD (policy ACCEPT) target prot opt source destination RH-Firewall-1-INPUT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT) target prot opt source destination
Chain RH-Firewall-1-INPUT (2 references) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT icmp -- anywhere anywhere icmp any ACCEPT esp -- anywhere anywhere ACCEPT ah -- anywhere anywhere ACCEPT udp -- anywhere 224.0.0.251 udp dpt:mdns ACCEPT udp -- anywhere anywhere udp dpt:ipp ACCEPT tcp -- anywhere anywhere tcp dpt:ipp ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ftp ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:smtp ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:nfs ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh ACCEPT udp -- anywhere anywhere state NEW udp dpt:netbios-ns ACCEPT udp -- anywhere anywhere state NEW udp dpt:netbios-dgm ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:netbios-ssn ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:microsoft-ds ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:https ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:telnet ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http ACCEPT udp -- anywhere anywhere state NEW udp dpt:domain REJECT all -- anywhere anywhere reject-with icmp-host-prohibited |
or
Chain INPUT (policy ACCEPT) target prot opt source destination RH-Firewall-1-INPUT all -- anywhere anywhere
Chain FORWARD (policy ACCEPT) target prot opt source destination RH-Firewall-1-INPUT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT) target prot opt source destination
Chain RH-Firewall-1-INPUT (2 references) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT icmp -- anywhere anywhere icmp any ACCEPT esp -- anywhere anywhere ACCEPT ah -- anywhere anywhere ACCEPT udp -- anywhere 224.0.0.251 udp dpt:mdns ACCEPT udp -- anywhere anywhere udp dpt:ipp ACCEPT tcp -- anywhere anywhere tcp dpt:ipp ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ftp ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:smtp ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:nfs ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh ACCEPT udp -- anywhere anywhere state NEW udp dpt:netbios-ns ACCEPT udp -- anywhere anywhere state NEW udp dpt:netbios-dgm ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:netbios-ssn ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:microsoft-ds ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:https ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:telnet ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http REJECT all -- anywhere anywhere reject-with icmp-host-prohibited |
# cat /etc/sysconfig/iptables
-> 내용 확인
# chkconfig --list iptables
-> 설정 정보 확인
[참고] 각 서비스들에 대한 제어 예제
(주의) 반드시 source ip 부분이나 destination ip 부분의 지정이 필요하다.
■ (WEB) HTTP -- TCP 80
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
■ (WEB) HTTPS -- TCP 443
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
iptables -A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 80,443 -j ACCEPT
■ (DB) MySQL -- TCP 3306
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
■ (FTP) active mode -- TCP 21,20
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
■ (FTP) passive mode -- TCP 21, 1024-65535
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 1024:65535 -j ACCEPT
■ (MAIL) SMTP -- TCP 25
iptables -A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
■ (MAIL) Secure SMTP -- TCP 465
iptables -A INPUT -p tcp -m tcp --dport 465 -j ACCEPT
■ (MAIL) POP3 -- TCP 110
iptables -A INPUT -p tcp -m tcp --dport 110 -j ACCEPT
■ (MAIl) Secure POP3 -- TCP 995
iptables -A INPUT -p tcp -m tcp --dport 995 -j ACCEPT
■ (MAIl) IMAP -- TCP 143
iptables -A INPUT -p tcp -m tcp --dport 143 -j ACCEPT
■ (MAIl) Secure IMAP -- 993
iptables -A INPUT -p tcp -m tcp --dport 993 -j ACCEPT
■ (ICMP) ICMP 허용 (ping)
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
■ (NTP) -- UDP 123
iptables -A INPUT -p udp --dport 123 -j ACCEPT
■ (DHCP) -- UDP 67,68
iptables -A INPUT -p udp --dport 67:68 –j ACCEPT
■ (SAMBA) -- TCP 445, 137,138,139
iptables -A INPUT -m state --state NEW -p tcp --dport 445 –j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 137:139 –j ACCEPT
[참고] 서버 취약점 보안에 대한 예제(EX: 홈게이트웨이, 홈라우터 설정시 참고)
(참고)
# sysctl -a
# cat /etc/sysctl.conf
■ 커널 패러미터 변경하는 작업 방법
# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
# sysctl -p
or
# sysctl -w net.ipv4.ip_forward=1
# sysctl -p
or
# echo 1 > /proc/sys/net/ipv4/ip_forward
# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
■ 커널 패러미터 관련 정보
/proc/sys/net/ipv4/ip_forward
-> net.ipv4.ip_forward
man sysctl
man sysctl.conf
■ NULL 패킷 차단 ---> (Scanning) TCP NULL Scan
NULL 패킷은 정찰(Scanning) 패킷으로 서버설정의 약한 곳(Port scan)을 찾기위한 방법으로 사용된다.
# iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
■ syn-flood attack 차단 ---> (DoS/DDoS) DoS Attack
syn-flood attack은 공격자가 새로운 연결을 만들고 빠지고를 반복해 리소스의 소모를 시킨다.
# iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
■ Anti synflood with iptables
Edit /etc/sysctl.conf to defend against certain types of attacks and append / update as follows:
net.ipv4.tcp_syncookies = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.netfilter.ip_conntrack_max = 1048576
■ XMAS 패킷 차단 ---> (Scanning) TCP Xmas Scan
XMAS 또한 정찰(Scanning) 패킷
# iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
■ MAC 주소로 제어
신뢰할 만한 ip와 MAC주소에 대해 모든 패킷을 허용
# iptables -A INPUT -s 192.168.0.3 -m mac --mac-source 00:50:80:FD:E6:32 -j ACCEPT
■ IP 주소로 제어
신뢰할 만한 ip에 대해 모든 패킷을 허용
# iptables -A INPUT -s 192.168.0.3 -j ACCEPT
신뢰할 만한 ip 대역에 대해 모든 패킷을 허용
# iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT
신뢰할 만한 ip 대역에 대해 모든 패킷을 허용
# iptables -A INPUT -s 192.168.0.0/255.255.255.0 -j ACCEPT
■ 포트 주소 범위로 지정
# iptables -A INPUT -p tcp --dport 6881:6890 -j ACCEPT
[참고] NAT(Network Address Translation) 대해서
[참고] http://blog.beany.co.kr/archives/2157
■ NAT 종류(Network 구분하는 경우)
* Normal NAT (사설 IP -> 공인 IP)
* Reverse NAT (공인 IP -> 사설 IP)
* Exclude NAT (NAT 적용하지 않는 host/Network 지정)
* Redirect NAT (특정 시스템으로 지정한 서비스 Forwarding)
■ NAT 종류(Network 구분하는 경우) 공인 IP 몇개를 물릴것인가?, 사설 IP가 고정되어 있는가?
* Dynamic NAT(N:1 or N:M)
여러개의 사설 IP : (여러개) 공인 IP
* Static NAT (1:1)
사설 IP : 공인 IP
■ NAT 종류(Network/Server 구분하는 경우) 어떤 주소(소스 주소/목적 주소)가 변경되는가?
* SNAT(Source NAT) : Source IP 주소 변경 (EX : 마스커레이딩)
* DNAT(Destination NAT) : Destination IP 주소 변경 (EX : Port Forwarding)
■ SNAT & DNAT
-i eth0 -o eth0
PREROUTING --> 라우팅 ----------------->POSTROUTING----->
(D-NAT) | (S-NAT)
| ^
| |
+-------> 로컬 프로세스 -----+
- Table(EX: NAT) -> Chain(EX: PREROUTING, POSTROUTING, OUTPUT) -> Rules
- PREROUTING(DNAT 경우, 패킷이 들어올때)
- POSTROUTING(SNAT 경우, 패킷이 나갈때)
■ SNAT 설정의 예
소스의 주소를 1.2.3.4로 변경하는 예
# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4
소스의 주소를 1.2.3.4 ~ 1.2.3.6로 변경하는 예
# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4-1.2.3.6
소스의 주소 1.2.3.4에 포트 1-1023로 변경하는 예
# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4:1-1023
마스쿼레이딩 설정(SNAT 방식의 특이한 경우)
# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE (N:1 방식, 유동IP/고정IP)
-> SNAT는 주로 고정 IP 방식에서 사용(eth0 : 회사가 보유한 고정/공인 IP)
-> DNAT는 주로 유동 IP 방식에서 사용(ppp0 : 통신 회사가 제공하는 유동/공인 IP)
■ DNAT 설정의 예
목적지 주소를 1.2.3.4로 변경하는 경우
# iptables -t nat -A PREROUTING -i eth1 -j DNAT --to 1.2.3.4
목적지 주소를 1.2.3.4 ~ 1.2.3.6로 변경하는 경우(부하 분산하는 경우)
# iptables -t nat -A PREROUTING -i eth1 -j DNAT --to 1.2.3.4-1.2.3.6
웹 트래픽에 대한 목적지 주소를 1.2.3.4의 8080 포트로 변경하는 경우
# itpables -t nat -A PREROUTING -p tcp --dport 80 -i eth1 -j DNAT --to 1.2.3.4:8080
1.2.3.4 목적지 주소로 가는 지역 패킷을 loopback으로 재설정 하기
# iptables -t nat -A OUTPUT -d 1.2.3.4 -j DNAT --to 127.0.0.1
방향재설정(Redirect) - Local Port Forwarding
# iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
DNAT 종류 중 예제 - Remote Port Forwarding
# iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j DNAT --to 1.2.3.4:8080
----------------------------------------------------------------------------------------
■ MASQERADE 설정
# iptables -t nat -A POSTROUTING -o eth0 -j MASQERADE
■ Network interface(eth0)을 통한 Port Forwarding
# iptables -t nat -A PREROUTING -p tcp -i eth0 --dport ${port} -j DNAT --to ${IP:Port}
■ 특정 IP를 통한 Port Forwarding
# iptables -t nat -A PREROUTING -p tcp -d ${IP} -j DNAT --to-destination ${IP:Port}
■ Local Port Forwarding
# iptables -t nat -A PREROUTING -p tcp -d ${IP} --dport ${Port} -j REDIRECT --to-port ${Port}
----------------------------------------------------------------------------------------
[참고] 방화벽 스크립트 만들기 예제(EX: 수업에서 사용한 명령어들의 묶음)
/root/bin/iptables.sh 스크립트
# cat /root/bin/iptables.sh
#!/bin/bash
iptables -F iptables -F -t nat
# # (1) Local ACCEPT # iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# # (2) Policy #
# # (2-1) TELNET Service # iptables -A INPUT -m state --state NEW -p tcp -s 192.168.10.149 -d 192.168.10.249 --dport 23 -j ACCEPT # # (2-2) SSH Service # iptables -A INPUT -m state --state NEW -p tcp -s 192.168.10.0/24 -d 192.168.10.249 --dport 22 -j ACCEPT # # (2-3) ICMP Service # iptables -A INPUT -p icmp --icmp-type echo-request -s 192.168.10.249 -d 0/0 -j ACCEPT iptables -A INPUT -p icmp --icmp-type echo-reply -s 0/0 -d 192.168.10.249 -j ACCEPT iptables -A INPUT -p icmp --icmp-type destination-unreachable -s 0/0 -d 192.168.10.249 -j ACCEPT # # (2-4) WEB Service # iptables -A INPUT -m state --state NEW -p tcp -s 0/0 -d 0/0 --dport 80 -j ACCEPT # # (2-5) NFSv4 Service # iptables -A INPUT -m state --state NEW -p tcp -s 192.168.10.149 -d 192.168.10.249 --dport 2049 -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp -s 192.168.10.149 -d 192.168.10.249 --dport 111 -j ACCEPT iptables -A INPUT -m state --state NEW -p udp -s 192.168.10.149 -d 192.168.10.249 --dport 111 -j ACCEPT # # (2-6) MAIL/POP3/IMAP4 Service # iptables -A INPUT -m state --state NEW -p tcp --dport 25 -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp --dport 110 -j ACCEPT iptables -A INPUT -m state --state NEW -p tcp --dport 143 -j ACCEPT # # (2-7) DNS Service # iptables -A INPUT -m state --state NEW -p udp --dport 53 -j ACCEPT # # (2-8) FTP Service # iptables -A INPUT -m state --state NEW -p tcp --dport 21 -A ACCEPT
# # (3) All DROP # iptables -P INPUT DROP |
(1) 서버 - 서비스(EX: 웹서버)
- 웹서비스(80)
- 원격접속 SSH(22)
- 파일전송 SFTP(22)
- ping(ICMP)
(2) 성능 이슈 - 서비스(EX: 웹서버)
- rules 개수를 줄일수 있는가?
- 주 서비스(EX: 웹서비스) rules은 가장 상단에 위치
[참고] 방화벽 스크립트 만들기 예제(EX: 실제 방화벽 스크립트 실무)
/root/bin/iptables.sh 스크립트(우분트 기준)
# cat /root/bin/iptables.sh
#!/bin/bash
## 현재 스크립트가 루트/sudo 권한으로 실행중인지 체크하고 그렇지 않을 경우 에러 메세지를 표시합니다. echo [*] Checking if run on the root... if [ `whoami` != root ]; then echo [!] Error : Please run this script as root or using sudo!! exit 1 fi
echo [*] Setting Up IPTABLES Rules...
echo [*] Applying Variables... OUTTER_INT=eth0 INNER_INT=eth1 INNER_NET=192.168.10.0/24
## 외부 IP 주소를 얻어옵니다. (이유는 NAT 정책에 설명해 놓은 글을 참고하시기 바랍니다.) ## ifconfig 출력 화면을 활용하여 현재 외부망으로 연결되어있는 인터페이스로 부터 외부 IP 주소를 얻어옵니다. ## 현재 IP주소는 root 계정의 홈폴더에 myip 라는 파일에 저장됩니다. echo [*] Getting current ip address from Outter Interface... ifconfig $OUTTER_INT > $HOME/myip.tmp1 sed "s/Bcast:/\n/" < $HOME/myip.tmp1 > $HOME/myip.tmp2 head -2 $HOME/myip.tmp2 | tail -1 > $HOME/myip.tmp3 sed "s/ \ \ \ \ \ \ \ \ \ inet\ addr://" < $HOME/myip.tmp3 > $HOME/myip rm -rf $HOME/myip.tmp* IP=$(cat $HOME/myip)
## 현재 iptables에 설정 되어 있는 항목들을 지웁니다. echo [*] Flushing current iptables rules... ### Flush ### iptables -F iptables -F -t nat iptables -X ## FTP Passive 모드 작동을 위한 모듈이 로드되어 있을 경우 해제합니다. modprobe -r ip_conntrack_ftp ## iptables 기본 정책들을 DROP으로 설정합니다. 이로써 허용한 패킷들 외에는 모두 차단됩니다. echo [*] Changing default policy to DROP... iptables -P INPUT DROP iptables -P OUTPUT DROP iptables -P FORWARD DROP
## INPUT 정책을 설정합니다. echo [*] Applying INPUT rules... ### INPUT ### ## Check Packets ## 들어온 패킷이 정상적으로 연결을 맺은 패킷이 아닐경우 차단합니다. iptables -A INPUT -m state --state INVALID -j DROP iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT ## Anti Spoofing ## 내부 주소로 부터 IP 스푸핑이 되는 것을 방지합니다. iptables -A INPUT -i $INNER_INT ! -s $INNER_NET -j DROP ## Accept ## 외부와 통신하기 위한 포트 번호들을 설정합니다. ## 다른 포트 번호 추가시 -p tcp 또는 -p udp 를 지정한 후 --sport 뒤의 포트 번호를 수정하여 추가해주시면 됩니다. ## 1443은 금융사이트 이용시 TouchEn key 라는 키보드 보안 프로그램을 위한 포트번호입니다. 해당 포트 번호가 차단되어 있을 경우 금융사이트를 원활히 이용하실 수 없습니다. ## 각 포트 번호들에 설명은 Forward 정책에 표시해 뒀으니 참고하시기 바랍니다. iptables -A INPUT -p tcp ! -s $IP --sport 20 -d $IP --dport 1024:65535 --syn -m state --state NEW -j ACCEPT iptables -A INPUT -p tcp ! -s $IP --sport 21 -d $IP --dport 1024:65535 --syn -m state --state NEW -j ACCEPT iptables -A INPUT -p tcp ! -s $IP --sport 80 -d $IP --dport 1024:65535 --syn -m state --state NEW -j ACCEPT iptables -A INPUT -p tcp ! -s $IP --sport 443 -d $IP --dport 1024:65535 --syn -m state --state NEW -j ACCEPT iptables -A INPUT -p tcp ! -s $IP --sport 465 -d $IP --dport 1024:65535 --syn -m state --state NEW -j ACCEPT iptables -A INPUT -p tcp ! -s $IP --sport 993 -d $IP --dport 1024:65535 --syn -m state --state NEW -j ACCEPT iptables -A INPUT -p tcp ! -s $IP --sport 1443 -d $IP --dport 1024:65535 --syn -m state --state NEW -j ACCEPT
iptables -A INPUT -p udp ! -s $IP --sport 53 -d $IP --dport 1024:65535 -m state --state NEW -j ACCEPT iptables -A INPUT -p udp ! -s $IP --sport 123 -d $IP --dport 1024:65535 -m state --state NEW -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT # from other to here iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT # from here to other
## OUTPUT 정책을 설정합니다. 기본 구조는 INPUT과 비슷하나 출발지와 목적지만 반대로 되어있다고 보시면 됩니다. ## 포트번호 추가시 INPUT 정책과 비슷한 방식으로 ACCEPT 부분에 -p tcp 또는 -p udp 지정 후 --dport 뒤의 포트 번호를 수정하여 추가해 주시면 됩니다. echo [*] Applying OUTPUT rules... ### OUTPUT ### ## Check Packets iptables -A OUTPUT -m state --state INVALID -j DROP iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT ## ACCEPT iptables -A OUTPUT -p tcp -s $IP --sport 1024:65535 ! -d $IP --dport 20 --syn -m state --state NEW -j ACCEPT iptables -A OUTPUT -p tcp -s $IP --sport 1024:65535 ! -d $IP --dport 21 --syn -m state --state NEW -j ACCEPT iptables -A OUTPUT -p tcp -s $IP --sport 1024:65535 ! -d $IP --dport 80 --syn -m state --state NEW -j ACCEPT iptables -A OUTPUT -p tcp -s $IP --sport 1024:65535 ! -d $IP --dport 443 --syn -m state --state NEW -j ACCEPT iptables -A OUTPUT -p tcp -s $IP --sport 1024:65535 ! -d $IP --dport 465 --syn -m state --state NEW -j ACCEPT iptables -A OUTPUT -p tcp -s $IP --sport 1024:65535 ! -d $IP --dport 993 --syn -m state --state NEW -j ACCEPT iptables -A OUTPUT -p tcp -s $IP --sport 1024:65535 ! -d $IP --dport 1443 --syn -m state --state NEW -j ACCEPT
iptables -A OUTPUT -p udp -s $IP --sport 1024:65535 ! -d $IP --dport 53 -m state --state NEW -j ACCEPT iptables -A OUTPUT -p udp -s $IP --sport 1024:65535 ! -d $IP --dport 123 -m state --state NEW -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT # from other to here iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT # from here to other
## FTP Passive 모드와 통신하기 위한 모듈을 로드합니다. echo [*] Loading FTP Passive Connection Tracking Module... ### Load FTP Passive Connection Tracking Module ### modprobe ip_conntrack_ftp
## Forward 정책을 설정합니다. ## 마찬가지로 포트번호 추가시 ACCEPT 부분에 -p tcp 또는 -p udp 지정 후 --dport 뒤의 포트 번호를 수정하여 추가해 주시면 됩니다. echo [*] Applying Forward rules... ### Forward ### ## Check Packets iptables -A FORWARD -m state --state INVALID -j DROP iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT ## Anti Spoofing iptables -A FORWARD -i $INNER_INT ! -s $INNER_NET -j DROP ## ACCEPT iptables -A FORWARD -p tcp -i $INNER_INT -s $INNER_NET --dport 20 --syn -m state --state NEW -j ACCEPT # ftp-control iptables -A FORWARD -p tcp -i $INNER_INT -s $INNER_NET --dport 21 --syn -m state --state NEW -j ACCEPT # ftp-data iptables -A FORWARD -p tcp -i $INNER_INT -s $INNER_NET --dport 80 --syn -m state --state NEW -j ACCEPT # http iptables -A FORWARD -p tcp -i $INNER_INT -s $INNER_NET --dport 443 --syn -m state --state NEW -j ACCEPT # https iptables -A FORWARD -p tcp -i $INNER_INT -s $INNER_NET --dport 465 --syn -m state --state NEW -j ACCEPT # smtp-ssl iptables -A FORWARD -p tcp -i $INNER_INT -s $INNER_NET --dport 993 --syn -m state --state NEW -j ACCEPT # imap-ssl iptables -A FORWARD -p tcp -i $INNER_INT -s $INNER_NET --dport 1443 --syn -m state --state NEW -j ACCEPT # TouchEn key
iptables -A FORWARD -p udp -i $INNER_INT -s $INNER_NET --dport 53 -m state --state NEW -j ACCEPT # dns iptables -A FORWARD -p udp -i $INNER_INT -s $INNER_NET --dport 123 -m state --state NEW -j ACCEPT # ntp
iptables -A FORWARD -p icmp --icmp-type echo-reply -j ACCEPT iptables -A FORWARD -p icmp --icmp-type echo-request -j ACCEPT
echo [*] Applying NAT rules... ### NAT ### ## 외부 주소를 내부 주소로 변환해 주기 위한 NAT 설정을 합니다. ## 보통 대부분 외부 주소는 부팅시 마다 IP 주소가 바뀌는 유동 IP로 지정되기 때문에 MASQUERADE 옵션을 사용하는데, 이 옵션은 대신에 CPU의 사용량이 많아 지게 집니다. ## 이렇게 되면 사양이 낮은 임베디드 장비의 경우 CPU 부하로 인해 인터넷 속도가 떨어지는 현상이 발생합니다. ## 따라서 저는 대신에 위에서 외부 IP 주소를 얻어오는 스크립트를 적용하였고 SNAT 옵션으로 외부 IP 주소를 고정적으로 설정하여 CPU 부하를 줄였습니다. iptables -t nat -A POSTROUTING -s $INNER_NET -o $OUTTER_INT -j SNAT --to-source $IP
## 공유기 설정을 위한 IP 포워딩 설정을 해줍니다. 이로써 외부주소를 내부주소로 변환하는 작업이 가능해 집니다. echo [*] Enabling IP fowarding... ### Enable IP Forwading ### echo 1 > /proc/sys/net/ipv4/ip_forward
echo [*] Setting Up IPTABLES Rules Finished!!!
exit 0 |
# vi /etc/rc.local
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing.
bash /root/bin/iptables.sh
exit 0 |
# ifdown eth0
# ifdown eth1
# ifup eth0
# ifup eth1
# bash /root/bin/iptables.sh
[*] Checking if run on the root... [*] Setting Up IPTABLES Rules... [*] Applying Variables... [*] Getting current ip address from Outter Interface... [*] Flushing current iptables rules... [*] Changing default policy to DROP... [*] Applying INPUT rules... [*] Applying OUTPUT rules... [*] Loading FTP Passive Connection Tracking Module... [*] Applying Forward rules... [*] Applying NAT rules... [*] Enabling IP fowarding... [*] Setting Up IPTABLES Rules Finished!!! |
[참고] 홈게이트웨어 서버, 홈라우터 서버
기타 기능
Firewall(NAT)
DHCP Server
DNS Server(Caching Only DNS Server)
NTP Client(or NTP Server)
+
보안기능
로드 제어(Load Balancing + QoS(Qaulity of Service))
VPN(EX: OpenVPN)
[참고] 홈게이트웨어 서버, 홈라우터 서버 구축시 기능에 대해서
홈게이트웨어 서버, 홈라우터 서버 구축시 기능에 대해서
Firewall(Packet Filtering)
Firewall(NAT)
DHCP Server
DNS Server(Caching Only DNS Server)
NTP Client(or NTP Server)
+
보안기능
로드 제어(Load Balancing + QoS(Qaulity of Service))
VPN(EX: OpenVPN)
|<--- WAN ----->| |<-------- LAN ------------>|
(Home Gateway Server)
--------------------- (EX: 192.168.0.0/24)
---------------- eth0 eth1 -----+---------+---------
--------------------- | |
xx.xx.xx.xx yy.yy.yy.yy | |
Linux Windows
[그림] 네트워크 구성도(예제)
WAN = eth0 with public IP xx.xx.xx.xx (EX: 5.5.5.5)
LAN = eth1 with private IP yy.yy.yy.yy (EX: 192.168.0.1)
1. NAT 구성 절차(CentOS 5.x 기준)
(1) Add 2 Network cards to the Linux box
(2) Verify the Network cards, Wether they installed properly or not
# ls /etc/sysconfig/network-scripts/ifcfg-eth* | wc -l
(3) Configure eth0 for Internet with a Public ( IP External network or Internet)
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 BOOTPROTO=none BROADCAST=xx.xx.xx.255 # Optional Entry HWADDR=00:50:BA:88:72:D4 # Optional Entry IPADDR=xx.xx.xx.xx NETMASK=255.255.255.0 # Provided by the ISP NETWORK=xx.xx.xx.0 # Optional ONBOOT=yes TYPE=Ethernet USERCTL=no IPV6INIT=no PEERDNS=yes GATEWAY=xx.xx.xx.1 # Provided by the ISP |
-> 통신회사에 따라
(ㄱ) DHCP 서버로 부터 공인 IP를 부여 받는 경우
(ㄴ) 직접 공인 IP를 부여하는 경우
(4) Configure eth1 for LAN with a Private IP (Internal private network)
# vi /etc/sysconfig/network-scripts/ifcfg-eth1
BOOTPROTO=none PEERDNS=yes HWADDR=00:50:8B:CF:9C:05 # Optional TYPE=Ethernet IPV6INIT=no DEVICE=eth1 NETMASK=255.255.0.0 # Specify based on your requirement BROADCAST="" IPADDR=192.168.2.1 # Gateway of the LAN NETWORK=192.168.0.0 # Optional USERCTL=no ONBOOT=yes |
# service network restart
(5) (Optional) Host Configuration
# vi /etc/hosts
127.0.0.1 nat localhost.localdomain localhost |
(6) Gateway Configuration
# vi /etc/sysconfig/network
NETWORKING=yes HOSTNAME=nat GATEWAY=xx.xx.xx.1 # Internet Gateway, provided by the ISP |
(7) DNS Configuration
# vi /etc/resolv.conf
nameserver 203.145.184.13 # Primary DNS Server provided by the ISP nameserver 202.56.250.5 # Secondary DNS Server provided by the ISP |
-> 통신 회사의 DNS 서버를 지정한다.
(8) NAT configuration with IP Tables
(ㄱ) Delete and flush. Default table is "filter". Others like "nat" must be explicitly stated.
# Flush all the rules in filter and nat tables
# iptables --flush (# iptables -F)
# iptables --table nat --flush (# iptables -t nat -F)
# iptables --delete-chain (# iptables -X)
(ㄴ) Delete all chains that are not in default filter and nat table
# iptables --table nat --delete-chain (# iptables -t nat -X)
(ㄷ) Set up IP FORWARDing and Masquerading
# iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
(# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE)
# iptables --append FORWARD --in-interface eth1 -j ACCEPT
(# iptables -A FORWARD -i eth1 -j ACCEPT)
(ㄹ) Enables packet forwarding by kernel
# vi /etc/sysctl.conf (# echo 1 > /proc/sys/net/ipv4/ip_forward)
[수정전] net.ipv4.ip_forward = 0 [수정후] net.ipv4.ip_forward = 1 |
# sysctl -p
# sysctl -a | grep ip_forward
(ㅁ) Apply the configuration
# service iptables save
# service iptables restart
# chkconfig iptables on
(9) Testing
(ㄱ) Ping the Gateway of the network from client system
# ping 192.168.2.1
(ㄴ) Try it on your client systems
# ping google.com
[참고] 인터넷상의 문서 참고(NAT 구성) |
■ Citrix XenServer ■ MS Hyper-V ■ RedHat KVM ■ VMware Esxi ■ Oracle OracleVM
■ XenServer 6.2
1. for eg. OVH gaves you server with one NIC (eth1) so this is first problem if you aren't using your own server. The answer to this is creating new external network with VLAN (i used 1024) on ETH1 (NIC1) and give this new network an IP in your XenCenter (Networking), for me 10.20.30.1 / 24 - why not :)
2. go to console of the serwer and check your interfaces i have (I won't write all):
eth1 - external network (OVH - with my static IP) - will call it EXT1 xapi0 - external network for internal use (our 10.20.30.0/24 network) - will call it INT1 xenbr1 - network bridge for vSwitch - all networks
you can check all information via ifconfig command
3. system changes a. Edit file /etc/sysctl.conf nano /etc/sysctl.conf b. Uncomment the following line to enable packet forwarding for IPv4 and other stuff
net.ipv4.ip_forward = 1net.ipv4.conf.default.proxy_arp = 1net.ipv4.conf.all.send_redirects = 0net.ipv4.conf.default.send_redirects = 0net.ipv4.conf.lo.send_redirects = 0net.ipv4.conf.xenbr0.send_redirects = 0net.ipv4.conf.default.rp_filter = 1net.ipv4.icmp_echo_ignore_broadcasts = 1net.ipv4.conf.default.accept_source_route = 0net.ipv4.conf.all.accept_redirects = 0net.ipv4.conf.all.send_redirects = 0kernel.sysrq = 1kernel.core_uses_pid = 1net.ipv4.tcp_syncookies = 1kernel.msgmnb = 65536kernel.msgmax = 65536kernel.shmmax = 4294967295kernel.shmall = 268435456vm.dirty_ratio = 5kernel.printk = 4 4 1 4
4. creating NAT
$IPTABLES -t nat -A POSTROUTING -s $INT1/255.255.255.0 -j MASQUERADE $IPTABLES -I RH-Firewall-1-INPUT -s $INT1/24 -j ACCEPT
PS. i made a bash script and added it to my starting scripts or you can use add it to /etc/sysconfig/iptables
5. testing
from my VM - ping google.com - OK
VM cofig: IP - 10.20.30.50 (static) gateway - 10.20.30.1 nameserver - 10.20.30.1
I could use command lokkit but in my case there is no MASQUERADE there, that ISP makes it hard as allways !!!
http://support.citrix.com/article/CTX123930 |
2. DHCP Server 구성(CentOS 5.X 기준)
① 인터페이스 구성 확인
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# 3Com Corporation 3c905B 100BaseTX [Cyclone] DEVICE=eth0 BOOTPROTO=dhcp HWADDR=00:50:04:84:4B:A4 ONBOOT=yes |
# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller DEVICE=eth1 BOOTPROTO=static HWADDR=00:1C:C0:C3:45:52 IPADDR=192.168.0.1 NETMASK=255.255.255.0 ONBOOT=yes HOTPLUG=no |
② DHCP 패키지 설치
# yum -y install dhcp dhclient
③ /etc/dhcpd.conf 파일 설정
# vi /etc/dhcpd.conf
# # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.sample # ddns-update-style interim; ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 { range 192.168.0.2 192.168.0.254; default-lease-time 43200; max-lease-time 86400; option routers 192.168.0.1; option subnet-mask 255.255.255.0; option broadcast-address 192.168.0.255; option domain-name-servers 168.126.63.1; } |
④ (Optional) 아이피 임대 로그 파일(/var/lib/dhcp/dhcpd.leases)
# mkdir -p /var/lib/dhcp
# touch /var/lib/dhcp/dhcpd.leases
⑤ 방화벽 수정(/etc/sysconfig/iptables)
# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-securitylevel # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :RH-Firewall-1-INPUT - [0:0] -A INPUT -j RH-Firewall-1-INPUT -A FORWARD -j RH-Firewall-1-INPUT -A RH-Firewall-1-INPUT -i lo -j ACCEPT -A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT -A RH-Firewall-1-INPUT -p 50 -j ACCEPT -A RH-Firewall-1-INPUT -p 51 -j ACCEPT -A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 67:68 -i eth1 -j ACCEPT -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited COMMIT |
⑥ DHCP 데몬 기동
# service dhcpd restart
3. NTP 설정
사설망 내부 서버들의 시간 동기화를 위해서, ntp 서버 데몬을 사용하는 방법입니다.
먼저 시간의 기준이 되는 서버를 선정합니다. 예로 그 서버가 192.168.100.15 라고 합니다.
그리고, 각 서버들이 192.168.100.x 네트워크에 속해있다고 가정합니다.
① 프로그램 설치
# yum -y install ntp
② /etc/ntp.conf 파일 수정
사설망내에서 시간의 기준이 되는 예로 192.168.100.15 번 서버는 /etc/ntp.conf 파일에서 다음 부분만 수정하여 설정합니다.
# vi /etc/ntp.conf
# Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap # 로컬 서버들이 시간 정보를 가져갈 수 있도록, 접근제한을 풀어줍니다.
# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.rhel.pool.ntp.org # 기존에 설정된 server 들을 모두 사용하지 않습니다. #server 1.rhel.pool.ntp.org # 오직 자체 시스템의 클럭만을 시간으로 사용합니다. (이 서버가 기준이므로,) #server 2.rhel.pool.ntp.org server <통신회사의 NTP 서버 IP> |
③ NTP 데몬 시작
# service ntpd restart
# chkconfig ntpd on
④ 방화벽 설정
# vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 123 -i eth1 -j ACCEPT
# service iptables restart
⑤ 테스트
# ntpq -pn
4. DNS 서버 설정(Caching Only DNS Server)
# yum -y install bind bind-utils bind-libs bind-chroot caching-nameserver
# service named restart
# chkconfig named on
■ 상용 방화벽에 대한 그림
6 | 참고 |
IPTables 최근 업데이트
http://www.netfilter.org/
IPTable 참고 사이트
http://wiki.centos.org/HowTos/Network/IPTables
RHEL 4 보안가이드
-http://stuff.mit.edu/afs/athena.mit.edu/project/rhel-doc/4/RH-DOCS/rhel-sg-ko-4/index.html
-https://access.redhat.com/site/documentation/ko-KR/Red_Hat_Enterprise_Linux/5/pdf/Deployment_Guide/Red_Hat_Enterprise_Linux-5-Deployment_Guide-ko-KR.pdf
리눅스를 방화벽이 적용된 공유기(Ubuntu/우분투, Debian/데비안 기준)
http://jollaman999.com/10
http://jollaman999.com/11
http://jollaman999.com/12
방화벽 설정(CentOS 기준)
http://webdir.tistory.com/170
Step-By-Step Configuration of NAT with iptables
http://www.howtoforge.com/nat_iptables
http://www.howtoforge.com/internet-connection-sharing-masquerading-on-linux
방화벽 시스템에 대한 소개
http://security3-3.tistory.com/2
'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글
20160801 TCP Wrapper (0) | 2016.08.01 |
---|---|
20160801 NTP (0) | 2016.08.01 |
20160728 방화벽 (0) | 2016.07.28 |
20160728 로그보안 (0) | 2016.07.28 |
20160727 로그보안 (0) | 2016.07.27 |