Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use iptables for off-machine backup / restore in Linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use iptables for different machine backup/recovery in Linux", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "How to use iptables for different machine backup/recovery in Linux"!

The method is as follows:

1. Location of iptables configuration file: /etc/sysconfig/iptables

Master computer: i.e. the machine in operation; backup machine: i.e. the machine switched to backup when the master computer fails

--Operation on the main control plane-------------------

2. Create a directory:

mkdir -p /bak/iptables/

mkdir /root/script/

3. Create a script in the/root/script/directory:

vi backup.sh

\cp /etc/sysconfig/iptables /bak/iptables/iptables_$(date +%Y%m%d%H)

4. Customized automatic tasks:

crontab -e

*/10 * * * * /usr/sbin/ntpdate 210.72.145.44

10 * * * * sh /root/script/backup.sh

--Operating on backup---------------------

5. Create a directory:

mkdir -p /bak/iptables/{lt,yd} #lt directory for connection jump backup, yd directory for mobile jump backup

mkdir /root/script/

6. Create a script in the/root/script/directory:

vi scp_lt.sh

#!/ usr/bin/expect -f

set password gst

spawn scp -P 22 root@202.105.135.52:/etc/sysconfig/iptables /bak/iptables/lt/iptables

set timeout 300

expect "root@202.105.135.52's password:"

set timeout 300

send "$password\r"

set timeout 300

send "exit\r"

expect eof

7. Create a script in the/root/script/directory:

vi scp_yd.sh

#!/ usr/bin/expect -f

set password gst

spawn scp -P 22 root@183.62.178.91:/etc/sysconfig/iptables /bak/iptables/yd/iptables

set timeout 300

expect "root@183.62.178.91's password:"

set timeout 300

send "$password\r"

set timeout 300

send "exit\r"

expect eof

8. Create a script in the/root/script/directory:

vi backup.sh

expect /root/script/scp_lt.sh

expect /root/script/scp_yd.sh

sed -i 's/202.105.135.52/183.62.178.85/g' /bak/iptables/lt/iptables

sed -i 's/58.251.49.18/58.250.56.154/g' /bak/iptables/lt/iptables

\cp /bak/iptables/lt/iptables /etc/sysconfig/iptables

/etc/init.d/iptables restart

/etc/init.d/iptables save

mv /bak/iptables/lt/iptables /bak/iptables/lt/iptables_$(date +%Y%m%d%H)

mv /bak/iptables/yd/iptables /bak/iptables/yd/iptables_$(date +%Y%m%d%H)

9. Note that you have to manually log in remotely once on the backup machine to obtain RSA's public key, and then you don't have to log in like this, otherwise the script will execute errors.

10. Customized automatic missions:

crontab -e

*/10 * * * * /usr/sbin/ntpdate 210.72.145.44

20 * * * * sh /root/script/backup.sh

At this point, I believe that everyone has a deeper understanding of "how to use iptables for different machine backup/recovery in Linux", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report