एक बार जब मैंने iptables को पोर्ट पोर्ट करने के लिए सेट किया, तो मैं इसे पूर्ववत कैसे करूं?


13

मैं कई साइटों पर पढ़ रहा हूं कि लिनक्स में एक पोर्ट से दूसरे पोर्ट को कैसे फिर से प्रयोग करें। उदाहरण के लिए, 80 से 8080 पोर्ट फिर से करना इस तरह दिखेगा ...

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 8080

मेरी चिंता यह है कि अगर मैं अपना विचार बदलूं तो क्या होगा? मैंने कहीं भी नहीं पढ़ा है जो इसे सही करने के लिए वाक्यविन्यास देता है। मुझे लगता है कि यह करने के लिए एक सरल (सरल) तरीका है, लेकिन मैं लिनक्स पर बहुत नया हूं, यह जानने के लिए कि ओएस को पुनः स्थापित किए बिना पोर्ट 80 को उसके मूल व्यवहार को कैसे पुनर्स्थापित किया जाए।

जवाबों:


6

आप अपनी जंजीरों से नियमों को हटाने के लिए iptables के लिए -D विकल्प का उपयोग कर सकते हैं । उदाहरण के लिए

पहले उस श्रृंखला को सूचीबद्ध करें जिसे आप किसी नियम को हटाना चाहते हैं, --line- संख्याओं का उपयोग करें

sudo iptables -L RH-Firewall-1-INPUT  -n --line-numbers

Chain RH-Firewall-1-INPUT (2 references)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
3    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           icmp type 255
4    ACCEPT     esp  --  0.0.0.0/0            0.0.0.0/0
5    ACCEPT     ah   --  0.0.0.0/0            0.0.0.0/0
6    ACCEPT     udp  --  0.0.0.0/0            224.0.0.251         udp dpt:5353
7    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:631
8    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:631
9    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
10   ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
11   REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

लाइन 6 को हटाने के लिए

sudo iptables -D RH-Firewall-1-INPUT 6
sudo iptables -L RH-Firewall-1-INPUT  -n --line-numbers

Chain RH-Firewall-1-INPUT (2 references)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
3    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           icmp type 255
4    ACCEPT     esp  --  0.0.0.0/0            0.0.0.0/0
5    ACCEPT     ah   --  0.0.0.0/0            0.0.0.0/0
6    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:631
7    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:631
8    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
9    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
10   REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

यदि आपके पास फ़ाइल में अपना iptables कॉन्फ़िगरेशन सहेजा गया है iptables-save, तो फ़ाइल ( , service iptables saveआदि) को अपडेट करना न भूलें ।


23

यदि आप स्क्रिप्टिंग कर रहे हैं, तो परिभाषा द्वारा निकालना आसान है:

उदाहरण:

जोड़ने के लिए:

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 8080

सूचना -ए ? इसका मतलब है जोड़ना

दूर करना:

iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to 8080

सूचना -D ? इसका मतलब है हटाना


यह बहुत उपयोगी था!
MadPhysicist

3

http://linux.die.net/man/8/iptables :

अहम

iptables -L, --list [chain]
    List all rules in the selected chain. If no chain is selected, all chains are listed. As every other iptables command, it applies to the specified table (filter is the default), so NAT rules get listed by

    iptables -t nat -n -L

    Please note that it is often used with the -n option, in order to avoid long reverse DNS lookups. It is legal to specify the -Z (zero) option as well, in which case the chain(s) will be atomically listed and zeroed. The exact output is affected by the other arguments given. The exact rules are suppressed until you use

    iptables -L -v

...

iptables -D, --delete chain rule-specification
iptables -D, --delete chain rulenum
    Delete one or more rules from the selected chain. There are two versions of this command: the rule can be specified as a number in the chain (starting at 1 for the first rule) or a rule to match. 

0

बिटवॉक का उत्तर सही है। चूंकि मेरे पास अभी भी इस पर टिप्पणी करने के लिए पर्याप्त बिंदु नहीं हैं, इसलिए मैं अतिरिक्त जानकारी को एक नए उत्तर के रूप में जोड़ रहा हूं:

एक नया नियम नियम जोड़ें

$ sudo iptables -t nat -D PREROUTING -p tcp --dport 443 -j REDIRECT --to 5671

सूची एनएटी नियम

$ sudo iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:https redir ports 5671

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination     

-t natस्विच नियम मार्ग के लिए सक्षम होना आवश्यक है।

नियम हटाएँ

$ sudo iptables -t nat -D PREROUTING -p tcp --dport 443 -j REDIRECT --to 5671
[ec2-user@ip-172-31-27-46 ~]$ sudo iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.