Dklab vzfirewallã¯
OpenVZã®ãŠãŒãã£ãªãã£ã§ãiptables-rulesã®é¢åãªå
¥åãä»®æ³ãã·ã³ã®å€ãã®IPã¢ãã¬ã¹ã«ãçµã³ä»ãããããšãªããã¡ã€ã¢ãŠã©ãŒã«ãæ§æã§ããŸãã ãŠãŒãã£ãªãã£ã®äž»ãªååã¯ãã§ããã ã䜿ããããããããšã§ãã ãŠãŒãã£ãªãã£ãäœæãããšãã«è¿œæ±ããç®æšã¯ãiptablesã®èšå®ã«é¢é£ããé çããã·ã¹ãã 管çè
ãæãããšã§ããã å°ãªããšãå°ãã¯æã«å
¥ãããšæããŸãã
ãã¡ãããå®çšŒåãµãŒããŒã§ããã«vzfirewallãè©Šãã®ã¯æããããããŸããã å¿
èŠãªããŒããéãããšãå¿ããã§ãããã ãããã£ãŠãvzfirewallããæãããã®ã䟿å©ãªã®ã¯ãOpenVZã䜿çšããŠæ°ãããµãŒããŒãã€ã³ã¹ããŒã«ãããšãã§ãïŒãŸãããŸãã¯devãµãŒããŒã«ïŒã ãã®åŸãåããå€ããããšãã§ããŸããäŸ
ã³ãŒããªã¹ã0ïŒã€ã³ã¹ããŒã« cd / usr / sbin
wget http://github.com/DmitryKoterov/vzfirewall/raw/master/vzfirewall
chmod + x vzfirewall
ã³ãŒããªã¹ã1ïŒ/etc/sysconfig/vz-scripts/101.confãã¡ã€ã« ...
PRIVVMPAGES = "300000ïŒ300000"
HOSTNAME = "example.com"
...
ãã¡ã€ã¢ãŠã©ãŒã«= "
ïŒãã¹ãŠã®ãã¹ãããHTTPããã³HTTPSããŒããžã®ã¢ã¯ã»ã¹ãèš±å¯ããŸãã
[80,443]
*
ïŒrelease.prodãã·ã³ããã®ã¿PostgreSQLããŒããžã®ã¢ã¯ã»ã¹ãèš±å¯ããŸãã
ïŒããã§ãã¡ã€ã³åã䜿çšã§ããããšã«æ³šæããŠãã ããã
[5432]
release.prod.example.com
release.test.example.com
ïŒDNSããŒãïŒ53 UDPïŒãžã®ã¢ã¯ã»ã¹ãèš±å¯ããŸãã
[udpïŒ53]
*
ïŒãµããããããSSHããã³SMTPãžã®ã¢ã¯ã»ã¹ãèš±å¯ããŸãã
[22.25]
192.168.10.0/24
192.168.11.0/24
ã
ã¯ããã¯ãããã®ãããªè€æ°è¡ã®FIREWALLãªãã·ã§ã³ã¯éåžžã®OpenVZ confãã¡ã€ã«ã«è¡šç€ºãããŸãã conf-fileãå€æŽãããšããiptablesã䜿çšããã³ãã³ãã確èªãããšããã§ãããã çŸåšã®æ§æã«è§Šããªãããã«ããã«ã¯ã次ã®ã³ãã³ããå®è¡ããŸãã
ã³ãŒããªã¹ã2ïŒãã¹ãïŒã©ã®ãããªå®éã®iptablesã«ãŒã«ãçæãããŸããïŒ ïŒvzfirewall -t
vzfirewallã䜿çšããŠããã¹ãŠã®confãã¡ã€ã«ã«ã«ãŒã«ãé©çšãã/ etc / sysconfig / iptablesã«ãæ°žä¹
ã«ãæžã蟌ãå¿
èŠããããŸãã å®è¡ïŒ
ã³ãŒããªã¹ã3ïŒã«ãŒã«ã®é©çš ïŒvzfirewall -a
ïŒãã®ã³ãã³ãã¯ãvzfirewallãæåŸã«éå§ãããŠããçºçãããéããŠããããŒãã®å€æŽã®ãªã¹ãã§ããDIFFãåºåããŸããïŒ
ç©çãã·ã³ã§ããŒããéãã«ã¯ããã¹ãã·ã¹ãã èšå®ãä¿åãã/etc/sysconfig/vz-scripts/0.confãã¡ã€ã«ã«FIREWALLãã£ã¬ã¯ãã£ããæžã蟌ãå¿
èŠããããŸãã
åæ
2005幎ã«ãã°ããã
OpenVZä»®æ³åã·ã¹ãã ã«åºäŒã£ãŠä»¥æ¥ããã®ããã®iptablesèšå®ã«èŠããã§ããŸãã ãããããã·ã¹ãã 管çè
ã¯ç§ãããç解ããŠããŸãã æ°ããä»®æ³ãã·ã³ãè¿œå ããããã³ã«ãiptablesã®ã«ãŒã«ã®æ°ãšè€éããåçã«å¢å ããæçµçã«/ etc / sysconfig / iptablesãã¡ã€ã«ïŒRHELã·ã¹ãã ã®å ŽåïŒãé
ãã¢ã³ã¹ã¿ãŒã«å€ãããIPã¢ãã¬ã¹ã®å€æŽïŒãå«ãç©çãã·ã³ã®å€æŽïŒ
vzmigrateãä»ããŠïŒ-äžå¯èœã§å±éºãªã¿ã¹ã¯ã«ã ä»®æ³ãã·ã³ã«å¯ŸããŠFORWARDãã§ãŒã³ã1ã€ãããªããããç¶æ³ã¯è€éã§ãïŒç©çãã·ã³ã®å Žåãæ§æã¯åçŽã§ãïŒå¯Ÿç§°çãªINPUTãšOUTPUTããããŸãïŒã
ããæç¹ã§ããããã§ååã§ãïŒããšèªåã«èšããŸããããããŠãå€æ¹ã«å°ããªãŠãŒãã£ãªãã£
vzfirewallãæžããŸããã ããã°ã©ã ã«ãã£ãŠè§£æ±ºãããäž»ãªã¿ã¹ã¯ã¯ãããŒãã³ãŒãã£ã³ã°ãããIPã¢ãã¬ã¹ã«çžãããããšãªãã1åã®æã®åãã§
å¿
èŠãªïŒããã³ä»ã®ããŒããéããïŒå€éšæ¥ç¶çšã®ããŒãã®ã¿ãéãããšã§ãã åæã«ãå€æŽãªãã®æ§æã¯ãéåžžã®vzmigrateã䜿çšããç©çãã·ã³ããå¥ã®ç©çãã·ã³ãžã®ç§»è¡ãããã³ãã·ã³ã®åèµ·åã«èããããšãã§ããŸãã
ãã¡ã€ã¢ãŠã©ãŒã«æ§æã¯ã/ etc / sysconfig / vz-scripts / *ãconfã«çŽæ¥ä¿åãããŸã
ãåãã®ããã«ãOpenVZã¯ä»®æ³ãã·ã³ã®èšå®ã/etc/sysconfig/vz-scripts/*.confãã¡ã€ã«ã«ä¿åããŸãïŒéRHEL OSã®å Žåããã¹ã¯ç°ãªãå ŽåããããŸãïŒã OpenVZã®é
åã¯ã1ã€ã®ç©çããŒãããå¥ã®ããŒãã«ä»®æ³ãã·ã³ã転éããã«ã¯ããã®confãã¡ã€ã«ãæ°ããå Žæã«ã³ããŒããã ãã§ãªãã/ vz / private / * /ã«ä¿åãããŠãããã·ã³ã®ãã£ã¬ã¯ããªèªäœãå§çž®ããŠè»¢éããããšã ãã§ã ããã¯ãvzmigrateãŠãŒãã£ãªãã£ã®åäœãšãŸã£ããåãã§ããåã«ãã¡ã€ã«ãã³ããŒããã ãã§ãã
vzfirewallãŠãŒãã£ãªãã£ã¯ãç¹å®ã®ä»®æ³ãã·ã³ãžã®çŽæ¥æ¥ç¶ãèš±å¯ãããŠããéããŠããããŒããšãã¹ãã®ãªã¹ãããconfãã¡ã€ã«ïŒ/etc/sysconfig/vz-scripts/*.confïŒã«ä¿åããŸãã ãªããªã vzmigrateã¯ãããç©çãã·ã³ããå¥ã®ãã·ã³ã«è»¢éãããšãã«ãã®ãã¡ã€ã«å
šäœãã³ããŒããŸãããã¡ã€ã¢ãŠã©ãŒã«ã®èšå®ã¯æ°ããå Žæã§èªåçã«æå¹ã«ãªããŸãã
IPã¢ãã¬ã¹ã§ã¯ãªãããã·ã³ã®DNSåã䜿çšããŸã
IPã¢ãã¬ã¹ã䜿çšããŠãã¡ã€ã¢ãŠã©ãŒã«ãæ§æããã®ã¯äžäŸ¿ã§ãã ãããã¯ãã·ã³ãããã·ã³ã«ç§»åãããšãã«å€æŽãããå¯èœæ§ããããŸããã€ãŸããæ§æãã¡ã€ã«ãå€æŽããå¿
èŠããããŸãã
vzfirewallãŠãŒãã£ãªãã£ã䜿çšãããšãã¢ã¯ã»ã¹ãèš±å¯ãããã·ã³ã®ãã¡ã€ã³åãæå®ã§ããŸãã ãã¡ããããããã®ååã¯vzfirewall -aã®ã«ãŒã«ãé©çšãããšãã«IPã¢ãã¬ã¹ã«å€æãããŸãããããã¯ãŠãŒã¶ãŒã«ééçã«è¡ãããŸãã
ç¹°ãè¿ããŸããããã·ã³åã§ã¯ãªãIPã¢ãã¬ã¹ã/ etc / sysconfig / iptablesãã¡ã€ã«ã«æ¢ã«å
¥ã£ãŠããŸãã ãããã£ãŠãOSã®èµ·åæã«DNSãµãŒããŒã䜿çšã§ããªãå Žåã§ãããã¡ã€ã¢ãŠã©ãŒã«ã¯åŒãç¶ãæ©èœããŸãã ãããŠããã¡ãããvzfirewallã¯ãè€æ°ã®IPã¢ãã¬ã¹ãäžåºŠã«æ¥ç¶ãããŠããDNSã¬ã³ãŒããåŠçã§ããŸãããã¹ãèµ·åã¢ãŒãïŒäœãé©çšãããŸããïŒ
vzfirewallãäºè¡ã¢ãŒãã§å®è¡ããŠããã¡ã€ã¢ãŠã©ãŒã«ã®ä»¥åã®ç¶æ
ãšæ¯èŒããŠé©çšãããã«ãŒã«ã確èªã§ããŸãã
ã³ãŒããªã¹ã4ïŒvzfirewallã®ãã¹ãå®è¡ã¢ãŒã ïŒvzfirewall -t
STDOUTã§ã¯ãããã°ã©ã ã¯ã«ãŒã«ã®æ°ãããªã¹ããåºåããSTDERRã§ã¯ãæ°ããããã³å€ãiptablesã³ãã³ãã»ããã®diffã³ãã³ãã®çµæãåºåããŸãã ãã®å Žåããã¡ã€ã¢ãŠã©ãŒã«ã®æ§æã¯å€æŽãããŸããã
ãã¡ã€ã¢ãŠã©ãŒã«ã®äžæçãªã·ã£ããããŠã³
vzfirewallãŠãŒãã£ãªãã£ã¯ãã«ãŒã«ã«ãšã©ãŒãå¥ã®èª€åäœããã£ãå Žåã§ãããã·ã³ãåžžã«å©çšå¯èœã§ããããšãä¿èšŒããŸãã ãããã£ãŠãããšãã°ãç©çãã¹ããã·ã³ã®ããŒã22ïŒSSHïŒã¯ãã«ãŒã«ã®æç¡ã«é¢ä¿ãªããåžžã«éãããŸãŸã«ãªããŸãã
蚺æã®ããã«ãã·ã³äžã®ãã¡ã€ã¢ãŠã©ãŒã«ãäžæçã«ç¡å¹ã«ããå¿
èŠãããå ŽåããããŸãïŒãã¹ãŠã®ããŒããéãïŒã ãããè¡ãã«ã¯ã次ã®ã³ãã³ããå®å
šã«äœ¿çšã§ããŸãã
ã³ãŒããªã¹ã5ïŒãã¡ã€ã¢ãŠã©ãŒã«å
šäœãäžæçã«ç¡å¹ã«ãã ïŒiptables --flush
ãã¡ã€ã¢ãŠã©ãŒã«ãå床æå¹ã«ããã«ã¯ã次ãå®è¡ããŸãã
ã³ãŒããªã¹ã6ïŒãã¡ã€ã¢ãŠã©ãŒã«ã匷å¶ãã ïŒvzfirewall -f -a
ããã§-fã¹ã€ããïŒ "force"ããïŒã¯éåžžã«éèŠã§ãã iptables --flushã®åŸã/ etc / sysconfig / iptablesãã¡ã€ã«ã®å
容ã¯å€æŽãããŸããã ããã¯ãvzfirewall -aãåçŽã«èµ·åããŠãçµæãåŸãããªãããšãæå³ããŸãããŠãŒãã£ãªãã£ã¯ããããããã¡ã€ã¢ãŠã©ãŒã«èšå®ãå€æŽãããŠããããäœãé©çšããªãããšãæ€åºããŸãã
æåãã¡ã€ã¢ãŠã©ãŒã«èšå®ãš$ãã®ãã¯ã
confãã¡ã€ã«ã®FIREWALLããããã£ã«ãã¹ãåãšããŒãçªå·ããªã¹ãããã ãã§ãªããç¹å®ã®ä»®æ³ãã·ã³ã«é©çšããããnakedãiptablesãã£ã¬ã¯ãã£ããæå®ããããšãã§ããŸãã ãã®å Žåããã¯ã$ THISã¯ããã·ã³ã®IPã¢ãã¬ã¹ãåç
§ããããã«äœ¿çšãããŸãã äŸïŒ
ã³ãŒããªã¹ã7ïŒiptablesã®æåã«ãŒã«ïŒ101.confãã¡ã€ã« ...
PRIVVMPAGES = "300000ïŒ300000"
HOSTNAME = "example.com"
...
ãã¡ã€ã¢ãŠã©ãŒã«= "
[ã«ã¹ã¿ã ]
ïŒãã®ãã·ã³IPã«çœ®ãæããããã$ THISããã¯ãã䜿çšã§ããŸã
ïŒïŒãããŠããã·ã³ã«å€ãã®IPãããå Žåãããã¯å€éåãããŸãïŒã
-Aå
¥å-i eth2 -d $ãã®-j ACCEPT
ïŒãŸãã¯ã$ THISãžã®åç
§ãªãã§ã³ãã³ãã䜿çšã§ããŸãïŒã®ã¿
ïŒãã®ãããªã³ãã³ãã¯0.confãã¡ã€ã«ã§èš±å¯ãããŠããŸãïŒã
-Aå
¥å-i eth1 -j ACCEPT
ã
ãã·ã³ã«è€æ°ã®IPã¢ãã¬ã¹ãããå Žåã¯ã©ããªããŸããïŒ ã³ãã³ãã«$ THISãå«ãŸããŠããå Žåãã¢ãã¬ã¹ã®æ°ã«å¿ããŠãã³ãã³ãã¯æ°åè€è£œãããŸãã ç©çãã·ã³ã§ïŒ0.confãã¡ã€ã«ã§ïŒæåã«ãŒã«ãæå®ãããŠããå Žåã$ THISã¯ãããã§äœ¿çšã§ããŸããã ããã¯vzfirewallãŠãŒãã£ãªãã£ã®æ©èœã§ãã ïŒãã ããç©çãã·ã³ã«ã¯INPUTãã§ãŒã³ãšOUTPUTãã§ãŒã³ã䜿çšãããä»®æ³ãã·ã³ã«ã¯FORWARDãã§ãŒã³ã®ã¿ã䜿çšããããããéåžžã¯åé¡ã¯çºçããŸãããïŒ
ãŸãšã
dklab vzfirewallãŠãŒãã£ãªãã£ã¯
ããã·ã³ãžã®çä¿¡æ¥ç¶ãå¶éããŸãã 圌女ã¯ãçºä¿¡æ¥ç¶ãå¶éããæ¹æ³ããã©ãã£ãã¯ãèæ
®ã«å
¥ããæ¹æ³ããã£ãã«åž¯åå¹
ãå¶éããæ¹æ³ãããŒããã©ã€ãããã©ãŒãããããæ¹æ³ãåµãæããæ¹æ³ãç¥ããŸããïŒãã ããæåŸã®ãã€ã³ãã¯éçºäžã§ãïŒã
ã€ã³ã¿ãŒãããã«ã¯åæ§ã®ããŒã«ãèšäºãå€æ°ãããŸãããç§ãèŠããã®ã«ã¯åãæ¬ ç¹ããããŸããè€éããšIPã¢ãã¬ã¹ãæ瀺çã«ãçµã³ä»ãããå¿
èŠããããŸãã
vzfirewallãŠãŒãã£ãªãã£ããŒãžãžã®ãªã³ã¯ïŒ
times ã vzenterãŠãŒãã£ãªãã£ãžã®ãªã³ã¯ãããã«ãããvzctl enterïŒ
twoã®æ¯æ¥ã®äœ¿çšãç°¡çŽ åãããŸãã