iptables 의 아주 기초적인 질문입니다.

zepinos의 이미지

오늘 임시로 방화벽을 좀 설치해야할 듯 해서 리눅스의 iptables 를 이용하려고 합니다.
가상 IP 부분(192.168.0.X)와 리얼 IP 몇 개만 열고 나머지 아이피는 전부 거부해버리고 싶은데요....

iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -s 123.231.213.132 -j ACCEPT (123.231.213.132 라는 리얼 IP 를 열고자할때)
...
iptables -A INPUT -s 0.0.0.0/24 -j DROP

와 같이 설정하는 것이 아닌가요?

그리고...iptables 룰을 바꾼 후에 다시 /etc/rc.d/init.d/iptables 스크립트를 재실행해줘야 하는건가요?

조언 부탁드립니다.

무한포옹의 이미지

는..

설정하는 방법이 여럿 있겠지만 설치되어 있는 /etc/init.d/iptables 스크립트를 이용한다면

/etc/sysconfig/iptables 를 수정하셔야 하고

수정한 뒤에는 restart 를 해주셔야 적용이 됩니다.

그리고 netmask 에 대한 이해가 필요한데요.. 0.0.0.0 즉 모든 IP에 대해 거부한다면

-s 0.0.0.0/24 가 아니고 -s 0.0.0.0/0 이 되어야 합니다.

그리고 저런식으로 DROP하는 것도 좋지만 기왕이면 iptables -P INPUT DROP

으로 INPUT 에 대한 기본 정책을 DROP으로 정하고 열어주는 룰을 추가하는 게 낫습니다.

-------------------------------
== warning 대부분 틀린 얘기입니다 warning ===

zepinos의 이미지

답변 감사드립니다.
그런데...닫아주고 난 뒤에 열어주라는 의미를 잘 모르겠네요.
먼저 적용된 것이 우선권을 가지기 때문에 먼저 전체를 닫아버리면 뒤에 여는 룰을 추가해도 안열리는것 아닌가요?

zepinos의 이미지

/etc/sysconfig/iptables 라는 화일이 존재하질 않는데요? -_-a

지리즈의 이미지

만들면 됩니다.

[admin@ns admin]$ cat /etc/rc.d/init.d/iptables | more
#!/bin/sh
#
# Startup script to implement /etc/sysconfig/iptables pre-defined rules.
#
# chkconfig: 2345 08 92
#
# description: Automates a packet filtering firewall with iptables.
#
# by bero@redhat.com, based on the ipchains script:
# Script Author:        Joshua Jensen <joshua@redhat.com>
#   -- hacked up by gafton with help from notting
# modified by Anton Altaparmakov <aia21@cam.ac.uk>:
# modified by Nils Philippsen <nils@redhat.de>
#
# config: /etc/sysconfig/iptables

# Source 'em up
. /etc/init.d/functions

IPTABLES_CONFIG=/etc/sysconfig/iptables

if [ ! -x /sbin/iptables ]; then
<중략> ...

There is no spoon. Neo from the Matrix 1999.

zepinos의 이미지

레드햇8을 풀로 깔았습니다.
좀 더 복잡한 시동 스크립트는 있습니다.
단지 설정에서 /etc/sysconfit/iptables 라는걸 이용해야 한다고 해서 찾던 중이었습니다.
제가 쉘 스크립트를 잘 몰라 분석은 잘 했는지 모르겠지만...
특별히 config 화일을 불러서 설정하는 것은 아닌듯 싶기도 하더군요.

켜 있는 동안만 작동되는 룰만 있어도 되는데...^^;;;

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.