티스토리 뷰

https://help.ubuntu.com/community/UFW


https://wiki.ubuntu.com/UncomplicatedFirewall?action=show&redirect=UbuntuFirewall


우분투가 ufw를 사용하고 있기는 하지만 iptables 정책에서 체인을 생성한 것과 같은 것 같다.


iptables 체인 위치는 

/etc/default/ufw: high level configuration, such as default policies, IPv6 support and kernel modules to use

/etc/ufw/before[6].rules: rules in these files are evaluated before any rules added via the ufw command

/etc/ufw/after[6].rules: rules in these files are evaluated after any rules added via the ufw command

/etc/ufw/sysctl.conf: kernel network tunables

/var/lib/ufw/user[6].rules or /lib/ufw/user[6].rules (0.28 and later): rules added via the ufw command (should not normally be edited by hand)

/etc/ufw/ufw.conf: sets whether or not ufw is enabled on boot, and in 9.04 (ufw 0.27) and later, sets the LOGLEVEL


실제 iptables -L 해보면 위에서 추가된 정책을 확인 할 수 있다.


추가적으로, iptstate 패키지도 설치하면 현재 세션 상태를 알 수 있다.


# sudo apt-get -y install iptstate



먼저 방화벽이 설치되어 있는지 확인해보고 없으면 설치


# dpkg -L ufw

# sudo apt-get -y install ufw



UFW 활성화/비활성화


# sudo ufw enable (활성화)

# sudo ufw disable (비활성화)



UFW 기본 정책


# sudo ufw default deny (기본정책 차단)

# sudo ufw default allow (기본정책 허용)



UFW 정책 확인


# sudo ufw status



허용 정책 추가


sudo ufw allow <port>/<optional: protocol>


들어오는 포트 53 허용(tcp, udp all)


sudo ufw allow port 53


53/tcp 허용


sudo ufw allow 53/tcp


53/udp 허용


sudo ufw allow 53/udp



차단 정책 추가


sudo ufw deny <port>/<optional: protocol>


들어오는 포트 53 차단


sudo ufw deny 53


들어오는 53/tcp 차단


sudo ufw deny 53/tcp



기존 정책 삭제


기존 정책 : ufw deny 80/tcp


sudo ufw delete deny 80/tcp



서비스 허용 정책 추가


서비스는 /etc/services 내역을 참조


sudo ufw allow <service name>


ssh 서비스 허용


sudo ufw allow ssh



서비스 차단 정책 추가


sudo ufw deny <service name>


ssh 서비스 차단


sudo ufw deny ssh



방화벽 로그 기록


sudo ufw logging on


sudo ufw logging off



출발지 IP 또는 목적지 IP 및 포트를 허용


sudo ufw allow from <ip address>


호스트 단위 또는 네트워크 단위 적용 가능


sudo ufw allow from 207.46.46.1


sudo ufw allow from 207.46.46.0/24



sudo ufw allow from <source ip address> to <destination ip address> port <port number>


192.168.0.4에서 22/all 프로토콜 접근 허용


sudo ufw allow from 192.168.0.4 to any port 22


댓글