0
我想每次在debian8上記錄網絡流量。
這是我的方式。如何在網關關閉前記錄淨流量何時關閉?
sudo vim /etc/systemd/system/graphical.target.wants/Ktraffic.service
[Unit]
Description=Record net traffic
[Service]
Type=oneshot
ExecStart=/bin/bash /etc/init.d/K01trafficLog.sh
[Install]
WantedBy=poweroff.target
sudo vim /etc/init.d/K011trafficLog.sh
#!/bin/bash
trafficlog="/var/log/traffic.log"
echo `date "+%Y-%m-%d %H:%M:%S "` >> $trafficlog
iptables -v -L INPUT |grep Chain >> $trafficlog
systemctl enable ktraffic.service
檢查流量日誌文件何時重新啓動。
sudo cat /var/log/traffic.log
2017-02-05 10:49:31Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
2017-02-05 11:40:25Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
沒有包記錄在/var/log/traffic.log中。
在執行/etc/init.d/K011trafficLog.sh之前網絡連接已關閉,如何在網絡連接完成之前使其執行?
哪個服務在關機期間關閉了網絡連接?
systemctl |grep net - vim
(standard input):sys-devices-pci0000:00-0000:00:1c.2-0000:03:00.0-net-eth0.device loaded active plugged RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
(standard input):sys-subsystem-net-devices-eth0.device loaded active plugged RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
(standard input):netfilter-persistent.service loaded active exited netfilter persistent configuration
(standard input):network-online.target loaded active active Network is Online
(standard input):network.target loaded active active Network
vim:sys-devices-pci0000:00-0000:00:1c.2-0000:03:00.0-net-eth0.device loaded active plugged RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
vim:sys-subsystem-net-devices-eth0.device loaded active plugged RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
vim:netfilter-persistent.service loaded active exited netfilter persistent configuration
vim:network-online.target loaded active active Network is Online
vim:network.target loaded active active Network
是否network.service在關機時關閉我的網絡?
sudo vim /etc/systemd/system/graphical.target.wants/Ktraffic.service
[Unit]
Description=Record net traffic
Before=networking.service
[Service]
Type=oneshot
ExecStart=/bin/bash /etc/init.d/K01trafficLog.sh
[Install]
WantedBy=poweroff.target
要重新啓動測試它,我的問題仍然存在。
我在/ var/log/syslog中設置了一個標誌。
echo "it is a flag here to get output info of poweroff " | sudo tee -a /var/log/syslog
重新啓動並獲取syslog如下。
[![enter image description here][1]][1]
哪些服務結果信息開始同步硬件時鐘系統時鐘?
您的要求是什麼?你能否提供你的要求樣本我/ P&O/P? – Inian
http://serverfault.com/q/785127/102883 –