Denne artikel er en spejling af maskinoversættelse, klik venligst her for at springe til den oprindelige artikel.

Udsigt: 14541|Svar: 1

[linux] iptables firewall tillader kun visse IP'er adgang til bestemte porte og specifikke hjemmesider

[Kopier link]
Opslået på 17/12/2015 22.02.49 | | |
1. Tag backup af iptables først

# cp /etc/sysconfig/iptables /var/tmp
Du skal åbne port 80 og angive IP- og LAN-adressen
Betydningen af følgende tre linjer:
Luk alle porte 80 først
Åbne 80 porte på IP-segmentet 192.168.1.0/24
Åbn 80 porte af IP-segmentet i IP-segmentet 211.123.16.123/24
# iptables -I INPUT -p tcp --dport 80 -j DROP
# iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT
# iptables -I INPUT -s 211.123.16.123/24 -p tcp --dport 80 -j ACCEPT
Ovenstående er en midlertidig løsning.
2. Gem derefter iptables
# service iptables gem
3. Genstart firewallen
#service iptables genstarter
===============Følgende er et genoptryk ================================================
Følgende er portene, alle blokeres, før nogle IP'er åbnes
iptables -I INPUT -p tcp --dport 9889 -j DROP
iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 9889 -j ACCEPT
Hvis NAT-videresendelse anvendes, husk at samarbejde med følgende for at træde i kraft
iptables -I FORWARD -p tcp --dport 80 -j DROP
iptables -I FORWARD -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT


De almindeligt anvendte IPTABLES-regler er som følger:
Du kan kun sende og modtage e-mails, alt andet er lukket
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -j DROP
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p udp --dport 53 -j ACCEPT
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p tcp --dport 25 -j ACCEPTER
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p tcp --dport 110 -j ACCEPT

IPSEC NAT-politik
iptables -I PFWanPriv -d 192.168.100.2 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 80 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:80
iptables -t nat -A PREROUTING -p tcp --dport 1723 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:1723
iptables -t nat -A PREROUTING -p udp --dport 1723 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:1723
iptables -t nat -A PREROUTING -p udp --dport 500 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:500
iptables -t nat -A PREROUTING -p udp --dport 4500 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:4500

NAT til FTP-server
iptables -I PFWanPriv -p tcp --dport 21 -d 192.168.100.200 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 21 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:21

Kun den angivne URL er tilladt
iptables -A Filter -p udp --dport 53 -j ACCEPT
iptables -A Filter -p tcp --dport 53 -j ACCEPT
iptables -A Filter -d www.3322.org -j ACCEPT
iptables -A Filter -d img.cn99.com -j ACCEPT
iptables -A Filter -j DROP

Nogle porte af en IP er åbne, og andre er lukkede
iptables -A Filter -p tcp --dport 80 -s 192.168.100.200 -d www.pconline.com.cn -j ACCEPT
iptables -A Filter -p tcp --dport 25 -s 192.168.100.200 -j ACCEPT
iptables -A Filter -p tcp --dport 109 -s 192.168.100.200 -j ACCEPT
iptables -A Filter -p tcp --dport 110 -s 192.168.100.200 -j ACCEPT
iptables -A Filter -p tcp --dport 53 -j ACCEPT
iptables -A Filter -p udp --dport 53 -j ACCEPT
iptables -A Filter -j DROP

Flere porte
iptables -A Filter -p tcp -m multiport --destination-port 22,53,80,110 -s 192.168.20.3 -j REJECT

Kontinuerlig port
iptables -A Filter -p tcp -m multiport --source-port 22,53,80,110 -s 192.168.20.3 -j AFVIS iptables -A Filter -p tcp --source-port 2:80 -s 192.168.20.3 -j AFVIS

Angiv tidspunktet for at surfe på internettet
iptables -A Filter -s 10.10.10.253 -m tid --tidstart 6:00 --timestop 11:00 --dage man, tirs, ons, torsdag, fre, lør, søn -j drop
iptables -A Filter -m tid --timestart 12:00 --timestop 13:00 --dage man, tirs, ons, torsdag, fre, lør, søn -j ACCEPTER
iptables -A Filter -m tid --timestart 17:30 --timestop 8:30 --dage man, tirs, ons, torsdag, fre, lør, søn -j accepter
Flere havnetjenester er forbudt
iptables -A Filter -m multiport -p tcp --dport 21,23,80 -j ACCEPT

NAT WAN-porten til PC'en
iptables -t nat -A PREROUTING -i $INTERNET_IF -d $INTERNET_ADDR -j DNAT --to-destination 192.168.0.1

NAT-port 8000 til 192. 168。 100。 200 porte af 80
iptables -t nat -A PREROUTING -p tcp --dport 8000 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:80

Porten, som MAIL-serveren ønsker at videresende
iptables -t nat -A PREROUTING -p tcp --dport 110 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:110
iptables -t nat -A PREROUTING -p tcp --dport 25 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:25

Kun PING 202 er tilladt. 96。 134。 133. Andre tjenester er forbudt
iptables -A Filter -p icmp -s 192.168.100.200 -d 202.96.134.133 -j ACCEPT
iptables -A Filter -j DROP
Deaktiver BT-konfiguration
iptables –A Filter –p tcp –dport 6000:20000 –j DROP
Deaktiver QQ-firewallkonfigurationen
iptables -A Filter -p udp --dport ! 53 -j DROP
iptables -A Filter -d 218.17.209.0/24 -j DROP
iptables -A Filter -d 218.18.95.0/24 -j DROP
iptables -A Filter -d 219.133.40.177 -j DROP
Baseret på MAC kan den kun sende og modtage e-mails og afvise alle andre
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -j DROP
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -p tcp --dport 25 -j ACCEPT
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -p tcp --dport 110 -j ACCEPT
Deaktiver MSN-konfiguration
iptables -A Filter -p udp --dport 9 -j DROP
iptables -A Filter -p tcp --dport 1863 -j DROP
iptables -A Filter -p tcp --dport 80 -d 207.68.178.238 -j DROP
iptables -A Filter -p tcp --dport 80 -d 207.46.110.0/24 -j DROP
Kun PING 202 er tilladt. 96。 134。 133 PING er ikke tilladt på andre offentlige netværks-IP'er
iptables -A Filter -p icmp -s 192.168.100.200 -d 202.96.134.133 -j ACCEPT
iptables -A Filter -p icmp -j DROP
Forbyd en MAC-adresse adgang til internettet:
iptables -I Filter -m mac --mac-source 00:20:18:8F:72:F8 -j DROP
Ping til en IP-adresse:
iptables –A Filter –p icmp –s 192.168.0.1 –j DROP
Forbyd en IP-adresse at servere:
iptables –A Filter -p tcp -s 192.168.0.1 --dport 80 -j DROP
iptables –A Filter -p udp -s 192.168.0.1 --dport 53 -j DROP
Kun visse tjenester er tilladt, andre afvises (2 regler)
iptables -A Filter -p tcp -s 192.168.0.1 --dport 1000 -j ACCEPT
iptables -A Filter -j DROP
En porttjeneste for en IP-adresse er forbudt
iptables -A Filter -p tcp -s 10.10.10.253 --dport 80 -j ACCEPT
iptables -A Filter -p tcp -s 10.10.10.253 --dport 80 -j DROP
Forbyd en porttjeneste for en MAC-adresse
iptables -I Filter -p tcp -m mac --mac-source 00:20:18:8F:72:F8 --dport 80 -j DROP
Forbyd en MAC-adresse adgang til internettet:
iptables -I Filter -m mac --mac-source 00:11:22:33:44:55 -j DROP
Ping til en IP-adresse:
iptables –A Filter –p icmp –s 192.168.0.1 –j DROP




Tidligere:Er det bedre at installere WordPress under Linux med Apache eller nginx?
Næste:Forskellen mellem en byte og et ord
 Udlejer| Opslået på 17/12/2015 22.16.55 |
iptables -I INPUT -p tcp --dport 3306 -j DROP
Service IPTable Save
Service IPTabels Restart
Ansvarsfraskrivelse:
Al software, programmeringsmaterialer eller artikler udgivet af Code Farmer Network er kun til lærings- og forskningsformål; Ovenstående indhold må ikke bruges til kommercielle eller ulovlige formål, ellers skal brugerne bære alle konsekvenser. Oplysningerne på dette site kommer fra internettet, og ophavsretstvister har intet med dette site at gøre. Du skal slette ovenstående indhold fuldstændigt fra din computer inden for 24 timer efter download. Hvis du kan lide programmet, så understøt venligst ægte software, køb registrering og få bedre ægte tjenester. Hvis der er nogen overtrædelse, bedes du kontakte os via e-mail.

Mail To:help@itsvse.com