Last active
February 15, 2017 00:50
-
-
Save hirolovesbeer/94a01ed25ee8802ae726a3811f1284c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CentOS 7.2におけるiptablesを用いたsyslog転送設定 | |
+-----+ +-----+ +-----+ | |
|host1| -> |host2| -> |host3| | |
+-----+ +-----+ +-----+ | |
- host1(10.0.0.1) = syslogを送信するホスト(send-syslog.py <- 自作syslog送信pythonプログラム) | |
- host2(10.0.0.2) = syslogを転送するホスト(iptablesのNAT設定) | |
- host3(10.0.0.3) = syslogを受信するホスト(rsyslog) | |
+ host2に以下を設定 | |
# iptables-servicesをインストール | |
$ sudo yum install iptables-services | |
$ sudo sysctl -w net.ipv4.ip_forward=1 <- パケット転送設定 | |
$ sudo sysctl net.ipv4.ip_forward <- 確認 | |
$ sudo iptables -t nat -F <- natルール初期化 | |
$ sudo iptables -t nat -A PREROUTING -i eno2 -p udp -d 10.0.0.2 --dport 514 -j DNAT --to-destination 10.0.0.3:514 | |
$ sudo iptables -t nat -nL -v | |
Chain PREROUTING (policy ACCEPT 54 packets, 4293 bytes) | |
pkts bytes target prot opt in out source destination | |
0 0 DNAT udp -- eno2 * 0.0.0.0/0 10.0.0.2 udp dpt:514 to:10.0.0.3:514 | |
- 必要であれば以下を入れる | |
$ sudo iptables -F <- ルールをクリア | |
or | |
$ sudo iptables -A INPUT -p udp --dport 514 -j ACCEPT <- syslogを開ける | |
+ host3で受信したログ | |
Dec 20 17:00:38 host1 send-syslog.py[1774]: Hey, it works 0 | |
Dec 20 17:00:38 host1 send-syslog.py[1774]: Hey, it works 1 | |
Dec 20 17:00:38 host1 send-syslog.py[1774]: Hey, it works 2 | |
Dec 20 17:00:44 host1 send-syslog.py[1803]: Hey, it works 0 | |
Dec 20 17:00:45 host1 send-syslog.py[1803]: Hey, it works 1 | |
Dec 20 17:00:45 host1 send-syslog.py[1803]: Hey, it works 2 | |
送信元ホストはhost1になる(host2の情報は出ない) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment