Backup and recovery methods for iptables rules

Source: Internet
Author: User
Linuxiptables: backs up and recovers instances from different machines. 1. the configuration file location of iptables is:/etc/sysconfig/iptables master control machine: a sub-machine in service running. backup machine: when the master machine fails, switch to the backup host-operations on the master machine ----------------- 2. create a directory: mkdir-p/bak/iptables/mkdir/

LinuxIptablesBackup and Recovery of instances from different machines

1. iptables configuration file location:/etc/sysconfig/iptables

Master control machine: the sub-machine in service operation; backup machine: when the master control machine fails, switch to the backup sub-machine

-- Operations on the master machine -------------------

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 _ $ (date + % Y % m % d % H)

4. Custom automatic tasks:

Crontab-e

*/10 */usr/sbin/ntpdate210.72.145.44

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

-- Operate on the backup machine ---------------------

5. create a directory:

Mkdir-p/bak/iptables/{lt, yd} # lt directory puts the link jump backup, yd directory puts the move jump backup

Mkdir/root/script/

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

Vi scp_lt.sh

#! /Usr/bin/CT-f

Set password gst

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

Set timeout 300

Your CT "root@202.105.135.52's password :"

Set timeout 300

Send "$ password \ r"

Set timeout 300

Send "exit \ r"

CT eof

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

Vi scp_yd.sh

#! /Usr/bin/CT-f

Set password gst

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

Set timeout 300

Your CT "root@183.62.178.91's password :"

Set timeout 300

Send "$ password \ r"

Set timeout 300

Send "exit \ r"

CT eof

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

Vi backup. sh

CT/root/script/scp_lt.sh

CT/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 _ $ (date + % Y % m % d % H)

Mv/bak/iptables/yd/iptables _ $ (date + % Y % m % d % H)

9. note: you must manually log on to the backup machine once to obtain the RSA public key. you do not need to log on to the backup machine. Otherwise, the script will run incorrectly.

10. Custom automatic tasks:

Crontab-e

*/10 */usr/sbin/ntpdate210.72.145.44

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.