date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,626,650,735,000
I have configured Postgres to accept network connections from anywhere: In pg_hga.conf: host all all 0.0.0.0/0 md5 In postgresql.conf: listen_addresses = '*' I can see the server is listening: vagrant@vagrant-ubuntu-trusty-64:~$ sudo netstat -ntlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name <snip> tcp 0 0 0.0.0.0:5433 0.0.0.0:* LISTEN 1570/postgres I've configured iptables to allow incoming TCP connections to 5433: vagrant@vagrant-ubuntu-trusty-64:~$ sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:5433 Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination From an ssh session in the VM, I can run telnet 10.0.2.15 5433 and it works. I can also connect with the full psql client. From my host, if I run the same telnet command or the same psql command, I can't connect. What can be wrong and what can I check?
The network adapter of your VM is by default in NAT mode. This means you can't ssh/telnet/etc to you VM from outside of it. Switch to Bridged in the VM settings and it should work.
Basic Hosting Postgresql in Virtualbox + Ubuntu 14.04
1,626,650,735,000
I am configuring a remote CentOS 7 webapp server to wrap https and ssh inside OpenVPN, while keeping smtp running outside of OpenVPN. I notice that, when I establish an OpenVPN connection from a Windows 7 Client using SecurePoint, I am only able to successfully connect to https : / / 10.8.0.1 and to ssh [email protected] when https and ssh are enabled BOTH in the public zone and in the private zone of firewalld. This seems wrong because all the OpenVPN activity should be running through port 1192. So how should I configure firewalld so that https and ssh are only allowed inside the VPN, but so that smtp can still function outside the VPN? The output of sudo firewall-cmd --list-all-zones is as follows. What should I remove from the following configuration, and what should I add to it to accomplish the goals stated in paragraph 1 above? Are there zones below from whom everything should be removed? block interfaces: sources: services: ports: masquerade: no forward-ports: icmp-blocks: rich rules: dmz interfaces: sources: services: ssh ports: masquerade: no forward-ports: icmp-blocks: rich rules: drop interfaces: sources: services: ports: masquerade: no forward-ports: icmp-blocks: rich rules: external interfaces: sources: services: ssh ports: masquerade: yes forward-ports: icmp-blocks: rich rules: home interfaces: sources: services: dhcpv6-client ipp-client mdns samba-client ssh ports: masquerade: no forward-ports: icmp-blocks: rich rules: internal interfaces: sources: services: dhcpv6-client https ipp-client mdns samba-client ssh ports: masquerade: no forward-ports: icmp-blocks: rich rules: rule family="ipv4" source NOT address="10.8.1.1" service name="ssh" reject public (default, active) interfaces: enp3s0 sources: services: dhcpv6-client https openvpn ssh ports: masquerade: yes forward-ports: icmp-blocks: rich rules: trusted interfaces: sources: services: ports: masquerade: no forward-ports: icmp-blocks: rich rules: work interfaces: sources: services: dhcpv6-client ipp-client ssh ports: masquerade: no forward-ports: icmp-blocks: rich rules:
You haven't added your tun0 device to any zone, so it defaults to the default zone, which in your case is the public zone. As root, run: firewall-cmd --zone=internal --add-interface=tun0 You can then leave ssh and https enabled in the internal zone and disable it in the public zone.
firewalld settings for OpenVPN with https, ssh, and smtp
1,626,650,735,000
I am new to virt-manager. After having configured a virtual network (new interface virbr0) with 2 VMs that should be able to communicate, I discovered that most ports are filtered. For example, the two nodes are mutually reachable via port 22, but for other ports, for example higher than 9000, I get a no route to host. trying to connect to the port 80, that is open on host 192.168.122.125, this is what I get with tcpdump: 07:50:55.363767 IP 192.168.122.14.54483 > 192.168.122.125.80: Flags [S], seq 21091821, win 14600, options [mss 1460,sackOK,TS val 313139 ecr 0,nop,wscale 7], length 0 07:50:55.364204 IP 192.168.122.125 > 192.168.122.14: ICMP host 192.168.122.125 unreachable - admin prohibited, length 68 Why is this? Is it possible to remove some filters, to allow at least the nodes to be able to communicate on various ports?
If you cannot reach another VM there are two possibilities: The target system blocks the connection with Netfilter (iptables). libvirt itself blocks on the virtualized LAN (not meaning VLAN), see http://libvirt.org/formatnwfilter.html In your case it should be a Netfilter problem. You can be sure about that by running tcpdump on the target host, too. you should see the same packets there. The solution is to adapt the iptables configuration but that is not related to Netfilter but to your distro. Thus you should make that a new question if you have problems with that.
libvirtd and filtered ports
1,626,650,735,000
iptables -A FORWARD -s 192.168.20.7 -d 10.10.48.3 -p tcp --dport 25 -o eth1 -j ACCEPT iptables -A FORWARD -s 10.10.48.3 -d 192.168.20.7 -p tcp --sport 25 -i eth1 -j ACCEPT Tuning the firewall of my organization I found these two lines which confused me. The eth1 interface is connected to the 10.10.x.x network, so... does it make sense to put the -o eth1 and the -i eth1 if that is already implied by the -d 10.10.48.3 and -s 10.10.48.3, respectively?
Based on the man page for iptables I'd be inclined to agree with your assessment as well. [!] -i, --in-interface name Name of an interface via which a packet was received (only for packets entering the INPUT, FORWARD and PREROUTING chains). When the "!" argument is used before the interface name, the sense is inverted. If the interface name ends in a "+", then any interface which begins with this name will match. If this option is omitted, any interface name will match. [!] -o, --out-interface name Name of an interface via which a packet is going to be sent (for packets entering the FORWARD, OUTPUT and POSTROUTING chains). When the "!" argument is used before the interface name, the sense is inverted. If the interface name ends in a "+", then any interface which begins with this name will match. If this option is omitted, any interface name will match. The last sentence in those descriptions is really the only point of concern. If there are other interfaces on the box traffic could be allowed by this rule to make use it, with the -o or -i options omitted. This is all assuming that the routing and such is setup to allow for that to even happen.
Does -o and -i make sense when the target host is already connected to the interface specified?
1,368,615,668,000
I have a linux webhosting server which attracts DDOS attacks. I want to use Cisco ASA 5500 Series Adaptive Security Appliances to protect the linux server from them. I know there are many factors should you know before you choose the suitable hardware firewall like the amount of this DDOS and pps ..etc Please suggest a linux tools to measure those factors and to help me collect the required informations ( pps - amount of DDOS - concurrent connections and other factors ).
Let's step back a bit... DDoS attacks involve hundreds or thousands of zombie machines on the internet that send traffic at your machine (usually faster than the server OR your ISP uplinks can process). The important piece here is that thousands of zombies sending traffic at your machine can consume 50Mpbs or a lot more, depending on the attack. If that DDoS traffic is more than your ISP bandwidth, no firewall on the planet can help you. You have to work with your upstream providers to track down the sources and shut down their traffic. This can take days. Some people attempt to use DNS to solve this problem (by using NAT from multiple providers and changing their DNS A record during an attack); this is not always the best solution, since the zombies often re-resolve DNS every so often to be sure they are hitting the right target. If you are simply handling DDoS situations that are smaller than your ISP uplink, then buy the Cisco ASA that can handle the bandwidth of the ISP uplink you have.
Linux tools to choose suitable Cisco ASA 5500
1,368,615,668,000
I am using the Cloudflare IPv4 and IPv6 lists to block all connections to my server from any IP that is not owned by Cloudflare. When I run sudo ufw status on the server I get: Status: active To Action From -- ------ ---- 80,443/tcp ALLOW 173.245.48.0/20 # Cloudflare IP 80,443/tcp ALLOW 103.21.244.0/22 # Cloudflare IP 80,443/tcp ALLOW 103.22.200.0/22 # Cloudflare IP 80,443/tcp ALLOW 103.31.4.0/22 # Cloudflare IP 80,443/tcp ALLOW 141.101.64.0/18 # Cloudflare IP 80,443/tcp ALLOW 108.162.192.0/18 # Cloudflare IP 80,443/tcp ALLOW 190.93.240.0/20 # Cloudflare IP 80,443/tcp ALLOW 188.114.96.0/20 # Cloudflare IP 80,443/tcp ALLOW 197.234.240.0/22 # Cloudflare IP 80,443/tcp ALLOW 198.41.128.0/17 # Cloudflare IP 80,443/tcp ALLOW 162.158.0.0/15 # Cloudflare IP 80,443/tcp ALLOW 104.16.0.0/13 # Cloudflare IP 80,443/tcp ALLOW 104.24.0.0/14 # Cloudflare IP 80,443/tcp ALLOW 172.64.0.0/13 # Cloudflare IP 80,443/tcp ALLOW 131.0.72.0/22 # Cloudflare IP 80,443/tcp ALLOW 2400:cb00::/32 # Cloudflare IP 80,443/tcp ALLOW 2606:4700::/32 # Cloudflare IP 80,443/tcp ALLOW 2803:f800::/32 # Cloudflare IP 80,443/tcp ALLOW 2405:b500::/32 # Cloudflare IP 80,443/tcp ALLOW 2405:8100::/32 # Cloudflare IP 80,443/tcp ALLOW 2a06:98c0::/29 # Cloudflare IP 80,443/tcp ALLOW 2c0f:f248::/32 # Cloudflare IP But when I run telnet xxx.xxx.xxx.xxx 80 from my local machine (being xxx.xxx.xxx.xxx the IP of the server) I get: Trying xxx.xxx.xxx.xxx... Connected xxx.xxx.xxx.xxx. So, looks like I am not getting blocked, when I should have been blocked as my local IP is not listed. Am I doing something wrong? UPDATE 1: I deployed another server just to do the same test and ensure that my IP is not white-listed. The result was the same. UPDATE 2: If I do tracepath xxx.xxx.xxx.xxx I get something similar to this (IPs and domains censured): 1?: [LOCALHOST] pmtu 1472 1: <MyComputerName>.mshome.net 0.576ms 1: <MyComputerName>.mshome.net 0.365ms 2: 10.0.0.1 0.790ms 3: my.isp.provider.com 8.934ms 4: <My.Public.IP.Address> 9.595ms asymm 5 5: no reply 6: an.isp.that.i.dont.know.com 33.937ms 7: same.isp.that.i.dont.know.com 46.866ms asymm 6 8: the.isp.that.i.dont.know.com 45.673ms asymm 5 9: <IP.Owned.By.Cloud.My.Provider> 42.138ms asymm 7 10: no reply 11: no reply 12: no reply 13: no reply 14: no reply 15: no reply 16: no reply 17: no reply 18: no reply 19: no reply 20: no reply 21: no reply 22: no reply 23: no reply 24: no reply 25: no reply 26: no reply 27: no reply 28: no reply 29: no reply 30: no reply Too many hops: pmtu 1472 Resume: pmtu 1472
The problem was that Docker opens exposed ports but they are not shown in UFW. Sorry I didn't mention Docker. I couldn't image it was related to it. See this thread: https://serverfault.com/questions/962012/ufw-not-blocking-incoming-traffic
UFW not blocking connection
1,368,615,668,000
192.168.100.50 is connected to 192.168.178.20 over the internet via wg0 interface. wg0 is opening up the tunnel 10.102.242.1/24. The wireguard client interface has 10.102.242.2. Through a static route on 192.168.100.1 I can connect from any device in 192.168.100.0/24 to the wireguard client using ssh [email protected] But I can only do this if I disable the ufw on the wireguard server. I tried to open port 22 on the server's ufw from anywhere, allowing it on wg0, allow IN and OUT. But nothing changed this. What do I not understand about this? To Action From -- ------ ---- 51820/udp ALLOW Anywhere # allow-wireguard 22 ALLOW 192.168.100.0/24 # SSH 22 ALLOW Anywhere # SSH test 22 on wg0 ALLOW Anywhere 22 (v6) ALLOW Anywhere (v6) # SSH test 51820/udp (v6) ALLOW Anywhere (v6) # allow-wireguard 22 (v6) on wg0 ALLOW Anywhere (v6) 22 ALLOW OUT Anywhere on wg0 22 (v6) ALLOW OUT Anywhere (v6) on wg0 Anywhere on eth0 ALLOW FWD 10.102.242.0/24 on wg0 traceroute 192.168.178.20 is also showing the same behaviour. With ufw active: traceroute to 192.168.178.20 (192.168.178.20), 64 hops max, 52 byte packets 1 192.168.100.1 (192.168.100.1) 2.824 ms 1.136 ms 1.016 ms 2 192.168.100.50 (192.168.100.50) 3.566 ms 1.557 ms 1.337 ms 3 * With ufw inactive it will instantly connect: 8 * * * 9 * 192.168.178.20 (192.168.178.20) 20.973 ms 16.469 ms
Some more testing brought my attention to the fact that I need to include the other remote subnet into the forwarding rule: ufw route allow in on eth0 out on wg0 to 192.168.178.0/24 Voilá!
Why is UFW blocking acces to SSH via Wireguard?
1,368,615,668,000
I have a Linux machine with ufw firewall, a program runs WS-Discovery that works as intended when ufw is disabled but fails to return anything when it is enabled, what I tried without success: Enabling outgoing traffic sudo ufw default allow outgoing Allowing both 3702/udp and 1900/udp What am I missing here?
I found couple of solutions: The first one using ipset as detailed in this answer to Stateful matching of multicast responses in iptables; replace 1900 with 3702 as that's the port used for WS-discovery. The second one which I used, is to allow incoming packets whose source port is 3702; with ufw you do it like this: ufw allow proto udp from 172.16.0.0/16 port 3702 to any
How to allow packets for WS-Discovery (onvif)?
1,368,615,668,000
I don't have direct control over the firewall. I'm trying to troubleshoot a connection to a SFTP site from a Unix machine. Pinging the host results in a timeout, and nmap is telling me the host may be down (although it is not). I suspect the outbound connection is being blocked by firewall settings - how can I confirm that this is indeed the issue?
Not much info, but here a guideline i would follow to debug this kind of issue if not in control of the firewall: Ping won't help, ICMP is a protocol that could be blocked as well somewhere/somehow along the path. Make a test using a different connection if applicable. Make a test connecting to other SSH/SFTP site. Eliminate protocol/configuration complexity and just try to telnet port 22 of remote host and see if cursor blinks or if you got ssh banner (in both cases connection is not blocked). Use tcpdump -i your_interface port 22 and watch for bidirectional traffic and 3 way handshake to happen.
Need to determine if firewall is blocking an outbound connection
1,572,647,506,000
There are a lot of network-related settings in /etc/sysctl.conf and a number of files in /etc/sysctl.d/. My data centre operator who has preconfigured the Ubuntu OS to work best in their environment has also added a custom file in there. I guess they come in a good state with the OS and I only need to make changes there if I have good reasons to do so. I don't fully understand all the details about the security issues they may cover so I'd rather not touch them. When I enable the firewall UFW (uncomplicated firewall), its config file says it will override these settings with its own copy in /etc/ufw/sysctl.conf. I have two questions regarding to that: Does this mean that all existing settings in the /etc/sysctl.conf file and /etc/sysctl.d/* files are completely ignored and only /etc/ufw/sysctl.conf is ever regarded? Or will anything mentioned in /etc/ufw/sysctl.conf just override the other existing settings (and nothing will happen if I comment away or delete all of its lines)? Why is a separate file used at all? The old files are still in place but possibly/partially unused or ineffective. That seems like very bad practice and a big source of errors and confusion. It is documented how I could stop this behaviour and switch back to the default file (it's unclear though what then happens to /etc/sysctl.d/*). Why should I not do this? And why is this not the default already? I couldn't find any information about these topics online. There are many places that explain that there are separate files with UFW and I should edit them instead. But noone explains why. I cannot make decisions without knowing the effects.
Here's a partial answer about what I found out so far. Reading the source code of UFW, I found it just loads in the settings from its own config file when UFW starts. This means that at this point, it will add all settings from that file to the already existing configuration. This will override just the values that are active in this file and will leave all other settings untouched. If this file is made empty, it will do nothing. I also checked each key in that file and found out that there are no overlaps for Ubuntu 18.04. Most settings are new (not included in the existing system files), only one or two will set the same key but also to the same value, so it won't change anything. Based on this, I decided to leave things as they are. Should I ever have to adjust something, I'll have to remember to check three locations: /etc/sysctl.conf /etc/sysctl.d/* /etc/ufw/sysctl.conf I still have no answer to the reasons behind this design yet. IMO, UFW should just have added their file in the /etc/sysctl.d directory. It also looks like (in the code) that UFW will never write to this file, so it's just one additional config file that's loaded and that the admin has to maintain. It appears not to be separated because UFW would want to write to it.
Why does UFW use a different sysctl.conf file?
1,572,647,506,000
I am attempting to use ebtables to match a specific VLAN ID (non zero) along with a specific VLAN PCP value. I tried the following: ebtables -A FORWARD -p 0x8100 --vlan-id 5 --vlan-prio 3 -j DROP Ebtables does not complain (as the check has been commented out in ebtables), but the rule reported back using "ebtables -L" only contained the match for VLAN ID. I did see in the ebtables man page that when vlan-prio is used, the vlan-id must either be zero or not specified. Why this is the case? I have so far not been able to find any references to support that the ID must be zero when the priority bits are used. Is there anyway to make this possible, aside from creating a separate chain to match the vlan-id and vlan-prio separately?
The explanation isn't really making sense, but here it is in the kernel at linux/net/bridge/netfilter/ebt_vlan.c: if (GET_BITMASK(EBT_VLAN_ID)) { if (!!info->id) { /* if id!=0 => check vid range */ if (info->id > VLAN_N_VID) { pr_debug("id %d is out of range (1-4096)\n", info->id); return -EINVAL; } /* Note: This is valid VLAN-tagged frame point. * Any value of user_priority are acceptable, * but should be ignored according to 802.1Q Std. * So we just drop the prio flag. */ info->bitmask &= ~EBT_VLAN_PRIO; } /* Else, id=0 (null VLAN ID) => user_priority range (any?) */ } So as far as I understand, kernel's side of ebtables enforces ignoring the prio (PCP) flag/option when receiving the rule with a non-null VLAN ID (VID), so I don't see how you can succeed without using an user chain with two rules as workaround. It's quite difficult to be able to consult without account any 802.1Q official document, but I couldn't find in the version from 2005 I could get to see an explanation for this comment. I understand it's written that VID=0 means there's only the PCP, but not that a PCP implies VID=0 nor that there is any interaction between both parameters (I mean there's nothing written about). Note: nftables doesn't have this limitation: nft add table bridge filter nft add chain bridge filter forward '{ type filter hook forward priority -200; policy accept; }' nft add rule bridge filter forward ether type vlan vlan id 5 vlan pcp 3 counter drop Will give back what was provided (debug bytecode included, here shown in little-endian, hence 0x81 instead of 0x8100 etc.): # nft --debug=netlink list chain bridge filter forward -a bridge filter forward 2 [ payload load 2b @ link header + 12 => reg 1 ] [ cmp eq reg 1 0x00000081 ] [ payload load 2b @ link header + 14 => reg 1 ] [ bitwise reg 1 = (reg=1 & 0x0000ff0f ) ^ 0x00000000 ] [ cmp eq reg 1 0x00000500 ] [ payload load 1b @ link header + 14 => reg 1 ] [ bitwise reg 1 = (reg=1 & 0x000000e0 ) ^ 0x00000000 ] [ cmp eq reg 1 0x00000060 ] [ counter pkts 0 bytes 0 ] [ immediate reg 0 drop ] table bridge filter { chain forward { # handle 1 type filter hook forward priority -200; policy accept; vlan id 5 vlan pcp 3 counter packets 0 bytes 0 drop # handle 2 } }
Matching vlan id and priority with ebtables
1,572,647,506,000
I need to add this 81.212.0.0/14 ip range to ipset. But it doesnt calculate lower than /16. I want to add from 81.212.0.0 to 81.215.255.255 IP addresses. Is there any other way but /14. Im trying to allow connections from a specific IP range. What I tried: ipset -A allowiplist 81.212.0.0/14 What I expected: That should allow connections between 81.212.0.0 - 81.215.255.255 P.S: All other rules works fine except but this. I think the problem is 81.212.0.0/14 have bigger IP count than 65535, maybe idk.
I think the problem is 81.212.0.0/14 have bigger IP count than 65535, maybe idk. You may be exactly correct here. If you are using an IPset of type hash, it has a maximal number of elements it can store, settable by the maxelem parameter when creating the IPset... and the default value for maxelem is 65536. And if you use a hash of type bitmap, 65536 addresses is the maximum size of the map. But what are you using the IPset for? If you are simply matching against the whole /14 segment, a hash-based IPset will be much less efficient than a simple network address & mask-based match. But if you are just setting up an initial set and planning to later selectively knock out specific IP addresses from it, then it would make sense to use an IPset. Even so, if the number of knocked-out IPs is expected to be relatively small, it might be sensible to invert the sense of whatever you're doing and use a mask-based match as the general rule and the IPset-based match as exceptions to it. Something like: iptables -N maybeAllow81_212 iptables -A maybeAllow81_212 -m set --match-set denyiplist_81_212 src -j DROP iptables -A maybeAllow81_212 -j ACCEPT iptables -A INPUT -s 81.212.0.0/14 -j maybeAllow81_212 This way, any traffic that is not coming from within the 81.212.0.0/14 can be processed in the main INPUT chain with essentially just two assembler instructions: one 32-bit AND and one 32-bit comparision. You cannot get much faster than that. Any traffic from within that segment gets diverted to the maybeAllow81_212 subchain which will do the hash match (with an inverted, hopefully much smaller set to match against with!) and then allow everyone who doesn't match the set to pass.
ipset How to add IP range from x to y
1,572,647,506,000
I created a bridge named eth2 with the interface gre1 between 2 virtual machines VM1 and VM2. The following is VM1 with bridge device eth2. # brctl show bridge name bridge id STP enabled interfaces eth2 8000.162f8564eb74 no gre1 The interface IP of VM1 is 172.80.1.1 and the interface IP of VM2 is 172.80.1.2 When iptables is stopped in VM1, I am able to ping the interface IP of VM2 from VM1. On starting iptables though, the ping will not work. # ping 172.80.1.2 PING 172.80.1.2 (172.80.1.2) 56(84) bytes of data. --- 172.80.1.2 ping statistics --- 6 packets transmitted, 0 received, 100% packet loss, time 5240ms Here is what my iptables looks like. # iptables -L -n -v Chain INPUT (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 72854 10M ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 /* 10defaults */ 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 /* 10defaults */ 75 5428 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED /* 10defaults */ 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 /* 20ssh */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 /* 30https */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 /* 30https */ 0 0 ACCEPT udp -- eth0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:162 /* 50snmp-health */ 0 0 ACCEPT udp -- eth0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:162 /* 50snmp-health */ 0 0 ACCEPT udp -- eth0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:123 /* 60ntp */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:5671 /* 70rabbitmq */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:3999 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4000 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4001 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4002 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4003 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4004 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4005 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4006 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4007 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4008 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4009 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4010 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4011 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4012 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4013 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4014 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4015 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4016 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4017 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4018 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4019 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4020 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4021 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4022 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4023 /* 80debug */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:15672 /* 85rabbitmq-ui */ 1250 250K REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 /* 99finish */ reject-with icmp-host-prohibited 0 0 ACCEPT udp -- eth2 * 0.0.0.0/0 0.0.0.0/0 udp dpt:162 /* eth2_RULE */ 0 0 ACCEPT tcp -- eth2 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:9990 /* eth2_RULE */ 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:9990 /* eth2_RULE */ 0 0 ACCEPT tcp -- eth2 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 /* eth2_RULE */ 0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp spt:53 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp spt:80 state ESTABLISHED 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp spt:443 state ESTABLISHED Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT all -- eth2 * 0.0.0.0/0 0.0.0.0/0 Chain OUTPUT (policy ACCEPT 72917 packets, 10M bytes) pkts bytes target prot opt in out source destination Also, sysctl -a | grep bridge-nf gives net.bridge.bridge-nf-call-arptables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-filter-vlan-tagged = 0 net.bridge.bridge-nf-filter-pppoe-tagged = 0 What could be causing this to not work? Is there something wrong with the iptable rules here?
I set the policy to accepted for my gre tunnel interface gre1. iptables -I INPUT -p gre -j ACCEPT This helped me to get it working.
Starting iptables stops communication between two virtual machines connected by a bridge
1,572,647,506,000
I have three virtual machines: A, B and C, all of them are running on debian. I have set up C to route traffic between A and B. Also C has two interfaces: enp0s3 and enp0s8, not sure if it's important in this case. The routing works fine. But now I want to set up iptables on the router to block all incoming requests except the ones that are sent to 8080 port. Here is what I do: iptables -P FORWARD DROP iptables -A FORWARD -p tcp --dport 8080 -j ACCEPT But then if I try to connect to any port (including 8080) on B from A using nc {host} {port}, my input is not being translated from A to B. I also tried it vice-versa: iptables -P FORWARD ACCEPT iptables -A FORWARD -p tcp ! --dport 8080 -j DROP but it doesn't work either. When I check the output of iptables -L -v there are some packets being accepted in FORWARD chain.
iptables -A FORWARD -p tcp --dport 8080 -j ACCEPT This rule will allow forwarding of all packets going to port 8080 However packets from port 8080 (Responses to the SYN Packet) are not forwarded unless the port making the request is also port 8080. As mentioned in one comment this is most likely not the case! You would need a second rule: iptables -A FORWARD -p tcp --sport 8080 -j ACCEPT this rule allows all packets comming from port 8080 to be allowed in forwarding as a recommendation i would add the ip adresses of the machines to the rules if you need more security in your setup, as with these 2 rules someone could talk to a different port as long as his source port is 8080. so my final rules would be: iptables -A FORWARD -p tcp --sport 8080 -s IPOFMACHINEA -j ACCEPT iptables -A FORWARD -p tcp --dport 8080 -d IPOFMACHINEA -j ACCEPT iptables -A FORWARD -p tcp --sport 8080 -s IPOFMACHINEB -j ACCEPT iptables -A FORWARD -p tcp --dport 8080 -d IPOFMACHINEB -j ACCEPT Since you didnt provide ips you will have to substitute them.
debian - iptables doesn't work for allowing one specific port
1,572,647,506,000
I found something weird in my debian 9 config. I changed my hostname by editing /etc/hostname and rebooting from "myhost" to "myhost-hello". Since this modification connecting to the machine via it's ip (I don't use WINS or other functions like that at all) shows the server not reacheable. I said myself.. maybe it's some kind of firewall issue, so I directly connected to the machine but the machine was still not reacheable via smb:// from an ubuntu test pc. I tried to reboot the samba daemon various times with any success.. When I switched the hostname of the target machine back to "myhost" samba returned available. I wonder.. is there some kind of automatic configuration of the hostname that makes samba not reacheable if the hostname changes? (note again that I connect to that machine via it's ip, and I don't use the wins feature or try to connect to it via it's hostname)
Seems that the error got solved editing also the /etc/hosts making the machine able to understand that the hostname must be searched locally instead being passed via the default gateway. So.. TL;DR: /etc/hosts edit the line myhost 127.0.0.1 for example to myhost-hello 127.0.0.1 ... that's all
Changing system hostname makes samba being unaccessible
1,464,869,156,000
My router currently provides the NAT to all the PCs and the Ubuntu desktop (with some server functions) in the network. I want to use the Ubuntu system as a proper firewall, but it only has one Ethernet interface. As such, I envision the following to get it running: Ubuntu/firewall router/WAN DHCP IP 192.168.1.1 192.168.1.10 192.168.1.* GW 192.168.1.10 WAN IP 192.168.1.1 Can I expect everything to work fine if I statically configure my Ubuntu system and router as I described? Will it be fine to use the single physical interface to handle INPUT and FORWARD? Do I need to do things like create virtual interfaces?
I've accomplished what I've described in the question. Here's the Ubuntu configuration that allowed me to do so: $ sudoedit /etc/network/interfaces auto eth0 iface eth0 inet static address 192.168.0.10 netmask 255.255.255.0 gateway 192.168.0.1 (Actually br0 in my files, from bridging VM to physical LAN, but I've replaced them with more generic eth0) $ sudoedit /etc/sysctl.conf # Uncomment the next line to enable packet forwarding for IPv4 net.ipv4.ip_forward=1 Basically, sysctl.conf's packet forwarding configuration is what, I believe, allowed my setup to work. I've confirmed that the setup indeed worked by seeing traceroutes going through 192.168.0.10 before 192.168.0.1 and the firewall rules configured on Ubuntu actually filtered the traffic as intended.
Route incoming and outgoing on same interface
1,464,869,156,000
This is about a cPanel server which, like most servers, is under constant attack from lands afar. Considering that I only host to clients in the US and Canada, there is less of a reason to allow full access to Asia and South America, among other areas. Too many firewall rules can increase latency, or worse, crash your firewall. Still, due to the large amount of attacks every day, I've configured CSF to manage at most 7000 rules. Some days are lighter than others, but on the 1st, 671 IPs were blocked trying to access SMTP (669) and cPanel (2). To try and get this under better control, I thought about only allowing web access to everyone, and blocking specific large blocks from accessing FTP or SMTP. So, here is what I've placed in the CSF pre-rules [/usr/local/csf/bin/csfpre.sh]. iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables -A INPUT -p tcp --dport 443 -j ACCEPT iptables -A INPUT -p tcp --dport 21:25 -s 1.0.0.0/8 -j DROP iptables -A INPUT -p tcp --dport 21:25 -s 2.0.0.0/8 -j DROP iptables -A INPUT -p tcp --dport 21:25 -s 112.0.0.0/8 -j DROP iptables -A INPUT -p tcp --dport 21:25 -s 113.0.0.0/8 -j DROP iptables -A INPUT -p tcp --dport 21:25 -s 117.0.0.0/8 -j DROP iptables -A INPUT -p tcp --dport 21:25 -s 190.0.0.0/8 -j DROP Now, I'm not entirely confident in my iptables skills, so I'd like opinions regarding this and certainly feedback if this is doing something bad. I do realize that this would block a massive amount of potential good email and any web developers in those areas hired to work on sites hosted on the server. My thought is that it is far far less probable that any valid email will be coming from these IP ranges. Also, I chose blocks based on my counts of attacks. Rather than load up the 6000-7000 actual IP blocks for Russia, for instance, I can reduce the firewall rules dramatically and keep it simple by only focusing on wholesale blocking entire Class A blocks. I used this site to examine exactly which countries would be blocked: tcpiputils.com
Alright, I've not gotten any good responses and it took trial and error, as well as monitoring to determine what works to achieve this. I found some things were said to be needed, so the example up above might not work on all systems because a full path should be used on the executables. Also, when specifying a range of ports, you need to add in --match multiport otherwise it will ignore the rule entirely. Lastly, I added in a shebang at the top to ensure that the script will be run correctly by shell. So here is the final version: /usr/local/csf/bin/csfpre.sh #!/bin/sh /sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT /sbin/iptables -A INPUT -p tcp --dport 443 -j ACCEPT /sbin/iptables -A INPUT -p all -s 60.168.112.0/20 -j DROP /sbin/iptables -A INPUT -p tcp --match multiport --dport 21:26 -s 1.0.0.0/8 -j DROP /sbin/iptables -A INPUT -p tcp --match multiport --dport 21:26 -s 112.0.0.0/7 -j DROP /sbin/iptables -A INPUT -p tcp --match multiport --dport 21:26 -s 116.96.0.0/12 -j DROP /sbin/iptables -A INPUT -p tcp --match multiport --dport 21:26 -s 116.118.0.0/16 -j DROP /sbin/iptables -A INPUT -p tcp --match multiport --dport 21:26,110,465,587,995 -s 117.0.0.0/8 -j DROP Now for the breakdown of what is going on on this cPanel server with CSF installed for a firewall. CSF allows adding custom rules that run in separate groups. All groups ultimately are run by iptables. First, csfpre.sh, then CSF, then csfpost.sh. Create a csfpre.sh file if it doesn't exist. You can put this in the /etc/ folder somewhere too, but it will always take the version in /usr/local/csf/bin/ with priority. Add the shebang at the top: !/bin/sh My plan is to do some port blocking via csfpre.sh, but rather than have it run through all the rules, I have it first detect whether the connection is for a webpage visit. By checking this first, it reduces the latency/response time. Ports 80 and 443 are for HTTP and HTTPS protocols, before anything else, if the input is for either of those ports, ACCEPT and stop checking rules for this csfpre group: /sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT /sbin/iptables -A INPUT -p tcp --dport 443 -j ACCEPT Now, we could just block entirely all other ports except for 80 and 443 if the next line is as such: /sbin/iptables -A INPUT -p all -s 60.168.112.0/20 -j DROP Since all web traffic is accepted already, this will not block the website traffic for that range. If this line came first, then it would block all traffic, including web traffic. I don't want to block good users from viewing websites by blocking all an entire subnet they are in. If blocking is reduced to specific ports, then we can block a specific port, a range, a list, or a combination of these. To only block FTP: /sbin/iptables -A INPUT -p tcp --dport 21 -s 1.0.0.0/8 -j DROP FTP actually uses a few different ports to establish a connection, and there also is SFTP/SSH which standardly is port 22 so better to block a range by using the starting port separated by a colon and then the ending port: /sbin/iptables -A INPUT -p tcp --match multiport --dport 21:26 -s 1.0.0.0/8 -j DROP You must use the --match multiport if you are using a range or a list. Lists can have no more than 15 ports, and each port in a range counts against the 15 total ports. You can also block the standard SMTP email ports: /sbin/iptables -A INPUT -p tcp --match multiport --dport 110,465,587,995 -s 117.0.0.0/8 -j DROP And, you can indeed use ranges in your list to block the FTP and mail ports in one rule: /sbin/iptables -A INPUT -p tcp --match multiport --dport 21:26,110,465,587,995 -s 117.0.0.0/8 -j DROP Save your script, and restart the firewall. Let CSF and cpHulk block individual IP addresses as needed. You can use your smartphone while not using your local connection to test with. Get the IP address of your phone, and be sure it is not the same as the computer you'll be working from. You can then run through all the scenarios, assuming you have the phone set up to check or send email through your server and an FTP program as well. For the blocking, I've decided to restrict entire subnets from accessing FTP, and for some, SMTP. In order to whittle it down, I've analyzed all the incoming alerts and then compared the worst subnets with the countries listed on this website: http://www.tcpiputils.com/browse/ip-address The end goal is to reduce the number of individual IPs being blocked by CSF. Blocking thousands of IPs can cause a latency issue, so by having some standard rules to block countries rife with malicious users reduces the need to manage such a large number of individual IPs. To recalculate valid subnet ranges, use this tool: http://www.subnet-calculator.com/cidr.php 112.0.0.0/7 spans 112.0.0.0 to 113.255.255.255, but 111.0.0.0/7 is invalid blocking, so it would be 110.0.0.0 to 111.255.255.255. It's important that you verify your subnet ranges so that you don't wind up blocking the wrong IPs.
Using IPTables to Block Ports to Class A Subnets While Allowing Web Ports (80/443)
1,464,869,156,000
I set up my Pi 2 as a wifi access point following this tutorial. I'd like to implement a rudimentary QoS, according to the DSCP field in every packet's header. That means, blocking packets using low priority services (for connected hosts sending, e.g., emails) and forwarding packets with high priority services (for connected hosts using, e.g., VoIP). I don't know where to start: how can I put in wait packets and then send them, or forward them if they are urgent? Technically, I have to listen for packets on my WiFi dongle (wlan0), see the DSCP field of every packet and then send them through the Ethernet cable (eth0) or put them in wait. I don't have a clue where to start. EDIT 1: according to my professor, checking the DSCP field won't be reliable, since it is not always filled with something. So I'll just look at the address, and see what service sent packets by checking the site's address.
libnetfilter_queue library from netfilter project seems the way: from netfilter.org: libnetfilter_queue is a userspace library providing an API to packets that have been queued by the kernel packet filter. It is is part of a system that deprecates the old ip_queue / libipq mechanism. I put packets in a queue with: sudo iptables -I FORWARD (parameters) -j NFQUEUE --queue-num x and with libnetfilter_queue I can access to packets stored in the queue above.
Blocking or forwarding packets as access point
1,464,869,156,000
I'm having a discussion with a software developer in my nears. He is using MySql direct connections for a software. There is no PHP/SSH/whatever-Bridge involved for the communication, neither at startup, while running or before logging out. The software goes from account login to management and so on. As you may know, the account data can be read out by some hacking software e.g. Cheat Engine. Thats the point we discussed after I created a web-based readonly interface for some data from this database. There is no security and everyone could just access to it and make with the data (mail addresses, passwords: sadly just md5) what they want. Now he told me that he configured the firewall and mysql server to I get mails from non-software (like my web interface) accesses to this database and an automatic backup. Now he is crying about a broken firewall and an overwhelmed mail server. Edit: Its a Debian-76-wheezy-64-LAMP My question is: Is this possible? My mind of this: No, its not as the client (with around 40 users) has always another IP and is logging in to the same mysql account as in my web interface. He is using that tactic to disallow complains about the mentioned security issues. I appretiate any help on that question. A little graphic:
I don't know which OS platform & version you are using But TCP Wrappers can help Edit your /etc/hosts.allow file #first Allow all local connections ALL: 127.0.0.1 #allow ssh Access to IPs this is important as you need to allow some users to login via ssh sshd: 1.1.1.1 sshd: 2.2.2.2 #change above Ips to your need then only those will have ssh access #Allow mysqld access i.e port 3306 to limited users mysqld: 1.1.1.1 mysqld: 2.2.2.2 #change above Ips to your need then only those will have ssh access In /etc/hosts.deny ALL:ALL #this will deny everything else In hosts.allow file you can add other services like proftpd, httpd, sendmail, access to only limited users & have some better control.
Linux firewall techniques: MySql-Account
1,464,869,156,000
I have a unique situation. Let's say my webserver ( e.g. 10.0.0.2) is connected to eth0 of my firewall (gw 10.0.0.1). A local network (192.168.0.0/24) is also connected to eth1 (192.168.0.1/24) of my firewall. Now I want to allow traffic from web server initialized from internal network. How should I use iptables command to do this? Is there a --state option that specifies INITIALIZED state?
You can try adding the following rules to your iptables firewall: $ sudo iptables -A INPUT -p tcp --dport 80 -s 192.168.0.0/24 -m state \ --state NEW,ESTABLISHED -j ACCEPT $ sudo iptables -A OUTPUT -p tcp --sport 80 -d 192.168.0.0/24 -m state \ --state ESTABLISHED -j ACCEPT
Allowing web server communication in Linux firewall
1,464,869,156,000
I have two ethernet interfaces, namely eth0 and eth1. I want to implement an advanced routing rule but I am totally new to firewall/routing rules in CentOS. Here is what I am trying to do: Both my interfaces are up and connected to internet. I want to be able to decide dynamically based on the type of traffic through which interface it should go out. For example, if it is HTTP traffic, I want it to use eth0 and if it is FTP etc traffic, I want it to use eth1, while different type of traffic could have the SAME destination IP address. How can I accomplish this task?
This Advanced Routing & Traffic Control HOWTO should have what you need. Once you setup your networks, you'll want to write some rules that will mark packets to go over the alternate connection in iptables (see Chapter 11 Netfilter & iproute - marking packets).
Firewall/routing rule in Centos for this setup
1,350,977,846,000
I have a problem with my nftables setup. I have two tables, each one has a chain with the same hook but a different name and priority. The tables are in different files which are loaded by an include argument. Because of the priority, I would think that the VPN-POSTROUTING chain will be executed before the INTERNET chain. But in my setup, the INTERNET chain is executed first. table ip nat { chain INTERNET { type nat hook postrouting priority srcnat + 1; policy accept; oifname br2 masquerade } } table ip vpn { chain VPN-POSTROUTING { type nat hook postrouting priority srcnat - 1; policy accept; oifname br2 ip saddr 10.0.0.0/24 ip daddr 192.168.0.0/24 accept } } where is my mistake? Edit: I changed the rules and add all chains to the same table, with the same result. In the next step, I followed A.B.'s advice and add counters and logs to the rules. The order of the chains corresponds to the priority, but the accept rule for the VPN is not triggered. When I add the VPN accept rule to the INTERNET chain, right before the masquerade rule, it works like expected.
Historically there used to be one NAT chain in a given hook (prerouting, input, output, ...). Executing a nat statement or simply accept-ing the packet being terminal for the chain, with a single chain it was also ending treatment within the hook. With nftables allowing to use more than one chain in the same hook, terminating a chain will just continue to the next chain. So if the first chain doesn't do anything (by accept-ing), the next chain gets its chance to do it instead, which is not what is intended. To solve this, the first chain (or any other chain) can leave a message passed to each next chain so it can act upon it: set a mark (an arbitrary value) for the next chain to change its behavior. Instead of accept which has zero effect (leaving the chain VPN-POSTROUTING empty also executes the default policy: accept), set a mark. So replace the rule in VPN-POSTROUTING with this one instead: nft add rule ip vpn VPN-POSTROUTING oifname br2 ip saddr 10.0.0.0/24 ip daddr 192.168.0.0/24 mark set 0xdeaf When this mark is set, it can then be used on the other chain to change behavior by not executing remaining rules. Insert this rule first in ip nat INTERNET: nft insert rule ip nat INTERNET mark 0xdeaf accept
nftables table and chain priority
1,350,977,846,000
I have a machine where I can connect it using ssh from different networks. But when I have moved to other country I have not be able to connect it. What may be the cause? I am able to ping the server but I get an error time out trying to do an ssh connection. UPDATE 1: Traceroute 1 1 ms 1 ms 1 ms <ip> 2 5 ms 1 ms 5 ms 192.168.10.1 3 5 ms 4 ms 6 ms 85.88.129.209 4 5 ms 4 ms 4 ms 85.88.144.97 5 15 ms 15 ms 17 ms te0-3-0-0-pr1.MAD.router.colt.net [212.74.87.17] 6 17 ms 14 ms 12 ms uni2-1.espanix.net [193.149.1.12] 7 * * * Time out. 8 * * * Time out. 9 * * * Time out. 10 * * * Time out. 11 * * * Time out. 12 41 ms 43 ms 38 ms <my_ip> Telnet: Connecting to <ip>... It cannot open connection to host on port 22. Connection error. SSh -v: Event Log: Writing new session log (SSH raw data mode) to file: file.log Event Log: Looking up host "<ip>" Event Log: Connecting to <ip> port 22 Event Log: Failed to connect to <ip>: Network error: Connection timed out Event Log: Network error: Connection timed out
This sounds like a firewall problem to me. Try using ssh with the -v flag for debugging output. This will give you a better clue as to what the problem may be. Also try to telnet to your ssh server on port 22 like this: telnet yourserver 22 You should get a response back with the ssh version number.
Connection Timeout for ssh connection depending to the ip location?
1,350,977,846,000
I'm new to ufw, and followed this link and entered exact command as instructed. ufw allow ssh 2222 Since my SSH is 2222, I want to add that rule in, but I kept getting ERROR: Need 'to' or 'from' clause Any hints for me ? I don't want to get lock out.
The ufw man says: Example rules using the simple syntax: ufw allow 53 This rule will allow tcp and udp port 53 to any address on this host. To specify a protocol, append '/protocol' to the port. For example: ufw allow 25/tcp This will allow tcp port 25 to any address on this host. ufw will also check /etc/services for the port and protocol if specifying a service by name. Eg: ufw allow smtp So if you say ufw allow ssh it is the equivalent of ufw allow 22/tcp In your case it would work if you put just ufw allow 2222 or ufw allow 2222/tcp since I guess you don't need udp...
UFW - Allow SSH in custom port
1,350,977,846,000
I have read all the man pages related to firewalld and also explored all of the files that come pre-installed in firewalld before it is configured. How can I configure the zones of the firewall to provide maximal security for a private web application? Here is the use case: 1.) Twenty known users will have http/https access to the web application from specific machines. 2.) One administrator will have remote ssh login access. 3.) The app will send and receive SSL email with the 20 users, the administrator, and with a known group of other users that will change over time and that will be defined by the users through the web application. 4.) The app includes a database, a war file, and uses various services. 5.) All usage not described in steps 1 through 4 will be blocked. My understanding is that I need to add interfaces to one or more zones, then add services to the zones that have interfaces. I also see that I can add source ip addresses to zones. I also see that I can use rich rules to define the configurations. But I have never configured a firewall before. Can someone show me how to translate the use case above into specific zones/interfaces/services/sources in firewalld on a remote CentOS 7 web server. Also, /etc/firewalld/firewalld.conf says that the default zone is public. What should the default zone be?
You should also check out this page on the Fedora Wiki. I think you will want to use the drop zone because it's the most strict way. create an advanced rule so that you can connect from your ip to port 22 (or your different ssh port) with firewall-cmd ---permanent -zone=home --add-forward-port=port=22:proto=tcp:toaddr=xxx.xxx.xxx.xxx and allow your own ip address with the next step firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="xxx.xxx.xxx.xxx" allow' for all the ip addresses add service http, https and so on (this is for all the users now) with firewall-cmd --permanent --zone=drop --add-service=<service> run firewall-cmd --reload to apply these permanent rules change your interface to drop with firewall-cmd --zone=drop --add-interface=<interface>, you might have to remove it from the previous zone (check it with firewall-cmd --list-all-zones if firewalld allows an interface to be in multiple zones which I don't know if you don't loose your ssh access everything should work and you have to run the last command again but now with the --permanent switch. But how do you want to allow access from a specific list of users in your web application? Of course the configuration I explained also only works if every user has a static ip address. EDIT: Here is a small explanation on the zones concept. This feature actually isn't so useful for servers but a better example are notebooks. You might want to automatically share your music via dlna when you are at home. In this case you will open the dlna port in the home zone and configure NetworkManager so that it switches your firewall zone to home if you are in your home WiFi or Ethernet LAN. However the default zone should be public because if you join a public wifi hotspot you automatically different rules for public networks where this share mustn't be enabled. If you want to reach a home server via ssh from outside your home network for example you wouldn't use firewall rules but other security technologies, the firewall should be configured in 'public' and allow connections from everywhere by default on the ssh port. To secure this highly attackable ssh access then you need to configure it to use client certificate authentication only and a program which is called fail2ban which recognizes and blocks brute force attacks because your ip changes when travelling. Web servers also have specific features to restrict access for example.
CentOS 7 Firewalld zone configuration for private web application
1,350,977,846,000
A newer server admin tried to set me up to authenticate SSH using a public key. It wasn't configured correctly, and SSH kept asking me for password (and he kept telling me to hit enter). Unexpectedly, I am no longer able to connect to the server at all on any port. (It is a public web server.) I spoke to the more senior Sysadmin and he couldn't figure out what happened. It feels very much like some service similar to fail2ban blocked the ip, but the sysadmin is sure it isn't on the server. (I also double checked systemctl and etc, and I don't see it.) Also there is no rule in iptables blocking my IP. Where are other places to look for something blocking the IP? (I've also checked /var/log but don't see any obvious log files that show the block.) Note: the server is in a Digital Ocean data center. I ran tracert, and the last IP it reported before timing out was 138.197.244.33 (which looks like a Digital Ocean front door).
After doing a lot of detective work and finally checking the list of running services more carefully: systemctl list-units --type=service --all | grep running I found that lfd.service (ConfigServer Firewall & Security - lfd) was running (not being a Linux sysadmin, I didn't know anything about it), and this turned out to be the culprit. The lfd.service does indeed monitor authentication failures and then blacklists IPs in /etc/csf/csf.deny. To remove the IP from the blacklist use: csf -dr <the IP> Here is a helpful guide to CSF.
After SSH authentication failures (Centos 7) something blocked my IP
1,350,977,846,000
I have a server that receives its IP address by DHCP. This seems to work and the connectivity is working (at the moment). However, I have not rebooted since installing a new /etc/sysconfig/iptables file so I could lose big upon the next reboot in case DHCP functionality depends on the connections now blocked. I have noticed that my firewall blocks outgoing UDP DHCP connections like this one: [22994.373788] Firewall: *UDP_OUT Blocked* IN= OUT=enup0 SRC=$OUR_IP DST=$DHCP_SERVER_IP LEN=328 TOS=0x00 PREC=0x00 TTL=64 ID=53942 DF PROTO=UDP SPT=68 DPT=67 LEN=308 UID=0 GID=0 This is presumably some DHCP client command like the request for a renewal of the DHCP lease? What happens if I block this outgoing request? If that is DHCP server implementation dependent: Does perhaps an RFC document demand I do not block this? Related: Do the firewall rules get initialised from /etc/sysconfig/iptables (by iptables.service) before or after the network is brought up during boot? I wish to block as much as possible otherwise I would just allow it instead of asking here.
The consequence of blocking that access is that your DHCP client will not be able to renew it's IP address lease until it expires. When the lease expires and the client still cannot reach the DHCP server by unicast, the DHCP client will unconfigure the current IP address, and then will start the DHCP request process from the beginning, using broadcasts so the packets will be addressed 0.0.0.0:68 -> 255.255.255.255:67. Because this violates normal IP addressing rules, on Linux the DHCP client will need to use raw sockets, which won't be blocked by regular iptables filter rules. Unless the network segment has an acute shortage of IP addresses, the DHCP server is likely to reissue your system the same IP address again when it receives the broadcast request. So, the overall effect will be that the system will still get its IP address, but you might experience a brief but totally unnecessary IP connectivity glitch each time the system's DHCP lease is due to expire.
Consequence of blocking outgoing UDP 68->67 (DHCP client)?
1,350,977,846,000
I have two computers, one is running Debian GNU/Linux 9 and the other Ubuntu 18.04.1 LTS. I have installed openssh on both computers. sudo apt install openssh-client sudo apt install openssh-server Now, I am able to use ssh to connect from Debian to Ubuntu, but not from Ubuntu to Debian. On the Debian computer nmap localhost outputs: Starting Nmap 7.40 ( https://nmap.org ) at 2019-01-24 14:39 CET Nmap scan report for localhost (127.0.0.1) Host is up (0.00010s latency). Other addresses for localhost (not scanned): ::1 Not shown: 999 closed ports PORT STATE SERVICE 22/tcp open ssh Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds I have also tried running sudo ufw allow ssh on the Debian computer. What should I do to be able to access either computer from the other? Edited in responce to comments Running netstat -l on the debian server outputs: b1012@debian:~$ netstat -l Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhost:5939 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN tcp6 0 0 [::]:ssh [::]:* LISTEN udp 0 0 0.0.0.0:mdns 0.0.0.0:* udp 0 0 0.0.0.0:40272 0.0.0.0:* udp 0 0 0.0.0.0:57967 0.0.0.0:* udp 0 0 0.0.0.0:bootpc 0.0.0.0:* udp6 0 0 [::]:mdns [::]:* udp6 0 0 [::]:41052 [::]:* raw6 0 0 [::]:ipv6-icmp [::]:* 7 Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 19723 /run/user/1000/pulse/native unix 2 [ ACC ] STREAM LISTENING 15627 /run/uuidd/request unix 2 [ ACC ] STREAM LISTENING 15630 /var/run/avahi-daemon/socket unix 2 [ ACC ] STREAM LISTENING 15633 /var/run/dbus/system_bus_socket unix 2 [ ACC ] STREAM LISTENING 16129 /tmp/ssh-AYHltf8zzAuv/agent.600 unix 2 [ ACC ] STREAM LISTENING 16960 /tmp/.X11-unix/X0 unix 2 [ ACC ] STREAM LISTENING 18495 /tmp/.ICE-unix/600 unix 2 [ ACC ] STREAM LISTENING 17542 @/tmp/dbus-0nAe1Vft unix 2 [ ACC ] STREAM LISTENING 16959 @/tmp/.X11-unix/X0 unix 2 [ ACC ] STREAM LISTENING 14138 @/tmp/dbus-kLaALJuH unix 2 [ ACC ] STREAM LISTENING 18494 @/tmp/.ICE-unix/600 unix 2 [ ACC ] STREAM LISTENING 14179 /run/user/1000/systemd/private unix 2 [ ACC ] STREAM LISTENING 14184 /run/user/1000/gnupg/S.gpg-agent.browser unix 2 [ ACC ] STREAM LISTENING 14187 /run/user/1000/bus unix 2 [ ACC ] STREAM LISTENING 14189 /run/user/1000/gnupg/S.gpg-agent unix 2 [ ACC ] STREAM LISTENING 14191 /run/user/1000/gnupg/S.gpg-agent.extra unix 2 [ ACC ] STREAM LISTENING 14193 /run/user/1000/gnupg/S.gpg-agent.ssh unix 2 [ ACC ] STREAM LISTENING 17539 /run/user/1000/keyring/control unix 2 [ ACC ] SEQPACKET LISTENING 1427 /run/udev/control unix 2 [ ACC ] STREAM LISTENING 14139 @/tmp/dbus-kLVeQt6a unix 2 [ ACC ] STREAM LISTENING 17311 /run/user/1000/keyring/ssh unix 2 [ ACC ] STREAM LISTENING 17313 /run/user/1000/keyring/pkcs11 unix 2 [ ACC ] STREAM LISTENING 9634 /run/systemd/private unix 2 [ ACC ] STREAM LISTENING 9648 /run/systemd/journal/stdout unix 2 [ ACC ] STREAM LISTENING 9653 /run/systemd/fsck.progress unix 2 [ ACC ] STREAM LISTENING 17541 @/tmp/dbus-yMrL8O3f unix 2 [ ACC ] STREAM LISTENING 18465 @/tmp/dbus-stZvWk5V9a unix 2 [ ACC ] STREAM LISTENING 17404 /var/run/NetworkManager/private-dhcp I get connection timed out, when trying to connect. ssh [email protected] -vvv OpenSSH_7.6p1 Ubuntu-4ubuntu0.1, OpenSSL 1.0.2n 7 Dec 2017 debug1: Reading configuration data /home/optoscale/.ssh/config debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug2: resolving "192.168.0.104" port 22 debug2: ssh_connect_direct: needpriv 0 debug1: Connecting to 192.168.0.104 [192.168.0.104] port 22. debug1: connect to address 192.168.0.104 port 22: Connection timed out ssh: connect to host 192.168.0.104 port 22: Connection timed out Running b1012@debian:~$ systemctl status ssh.service Outputs: ● ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab Active: active (running) since Thu 2019-01-24 13:42:23 CET; 2h 0min ago Process: 3594 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCES Process: 3589 ExecReload=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS) Main PID: 2332 (sshd) Tasks: 1 (limit: 4915) CGroup: /system.slice/ssh.service └─2332 /usr/sbin/sshd -D
You have a NAT firewall between your two machines. You can see this because your Debian system's IP address is 192.168.0.24 but the Ubuntu system sees the associated inbound connection coming from 10.20.81.24. Unless you control and manage this NAT firewall, it will be impossible for you to connect directly from your Ubuntu server to your Debian server. (Various work-arounds exist, including running autossh on your Debian system with a reverse tunnel, or OpenVPN initiated from Debian to Ubuntu. Either can allow connections to be made back the other way.)
ssh works only one way
1,350,977,846,000
I am trying to only allow SSH incoming and outgoings on my firewall, but the problem is that FTP can also be used even though I DROP at the end of the script # Incoming SSH $iptables -A INPUT -p tcp --dport ssh -j ACCEPT # Outgoing SSH $iptables -A OUTPUT -p tcp --dport ssh -j ACCEPT The way I DROP is by: iptables -A INPUT -j DROP iptables -A OUTPUT -j DROP iptables -A FORWARD -j DROP The result of iptables -L: Chain INPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere ctstate ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ACCEPT tcp -- anywhere anywhere tcp dpt:http ACCEPT tcp -- anywhere anywhere tcp dpt:https ACCEPT udp -- anywhere anywhere udp dpt:bootpc DROP all -- anywhere anywhere Chain FORWARD (policy DROP) target prot opt source destination DROP all -- anywhere anywhere Chain OUTPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere ctstate ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ACCEPT udp -- anywhere anywhere udp dpt:domain ctstate NEW ACCEPT tcp -- anywhere anywhere tcp dpt:domain ctstate NEW ACCEPT tcp -- anywhere anywhere tcp dpt:http ACCEPT tcp -- anywhere anywhere tcp dpt:https DROP all -- anywhere anywhere SCRIPT: #!/bin/bash iptables=/usr/sbin/iptables $iptables -F $iptables -P INPUT $iptables -P OUTPUT $iptables -X $iptables -F -t nat $iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE $iptables -A INPUT -i lo -j ACCEPT $iptables -A OUTPUT -o lo -j ACCEPT $iptables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT $iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT $iptables -A INPUT -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT $iptables -A OUTPUT -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT $iptables -A OUTPUT --p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT $iptables -A INPUT -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
The first line of each of your INPUT and OUTPUT chains accepts everything. You can remove them with these two commands iptables -D INPUT 1 iptables -D OUTPUT 1 But be sure you will still have access (ideally physically at the console) before running them. Now you've provided your script it's possible to suggest alternatives #!/bin/bash -e PATH=/usr/sbin:$PATH # Reset to a sane state, even if just temporarily iptables -P INPUT ACCEPT iptables -P OUTPUT ACCEPT # Erase all the rules iptables -F iptables -t nat -F # Simple NAT rule for outgoing traffic iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # Allow loopback iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT # Allow the return half of established connections iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # Allow incoming and outgoing ssh iptables -A INPUT -p tcp --dport 22 -j ACCEPT iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT # You probably want other stuff permitted here such as DNS on 53/udp and 53/tcp # and maybe NTP on 123/udp # iptables -A OUTPUT -p udp --dport 53 -j ACCEPT # iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT # iptables -A OUTPUT -p udp --dport 123 -j ACCEPT # Default policy is to discard all traffic iptables -P INPUT DROP iptables -P OUTPUT DROP
Only allow SSH incoming and outgoing
1,350,977,846,000
I want to make a bunch of websites unaccessible on my computer. My hosts.allow file: sendmail: all # /etc/hosts.allow: list of hosts that are allowed to access the system. # See the manual pages hosts_access(5) and hosts_options(5). # # Example: ALL: LOCAL @some_netgroup # ALL: .foobar.edu EXCEPT terminalserver.foobar.edu # # If you're going to protect the portmapper use the name "rpcbind" for the # daemon name. See rpcbind(8) and rpc.mountd(8) for further information. My hosts.deny file: # /etc/hosts.deny: list of hosts that are allowed to access the system. # See the manual pages hosts_access(5) and hosts_options(5). # # Example: ALL: some.host.name, .some.domain # ALL EXCEPT in.fingerd: other.host.name, .other.domain # # If you're going to protect the portmapper use the name "rpcbind" for the # daemon name. See rpcbind(8) and rpc.mountd(8) for further information. # # The PARANOID wildcard matches any host whose name does not match its # address. # # You may wish to enable this to ensure any programs that don't # validate looked up hostnames still leave understandable logs. In past # versions of Debian this has been the default. # ALL: PARANOID ALL: .vk.com ALL: .ria.ru ALL: facebook.com My hosts file: 127.0.0.1 localhost 127.0.0.1:82 testsecond 127.0.1.1 shc 127.0.2.2:81 someth.com 127.0.2.2:83 test # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet fe00::0 ip6-mcastprefix fe02::1 ip6-allnodes fe02::2 ip6-allrouters I do follow all recommendations about settings hosts* files and I still CAN access them. I must do something really stupid or wrong. For me it looks like they are just ignored.
hosts.deny is for servers, not clients running on your computer therefore you can't block websites with it. I suggest reading the hosts_access(5) man page for your system (Debian version, FreeBSD version). By the way, there's a proposal by Lennart Poettering to get rid of tcpwrappers/tcpd in Fedora and OpenSSH will do the same.
Linux hosts.deny settings are not applied
1,350,977,846,000
I'd like to establish a connection between my client and raspbian. Within my network, I can connect to my service at any time without any problems. Now I want to connect to my service via the internet. This is unfortunately not working when I try to use my internet ip for the connection. client = new MqttClient("tcp://77.777.77.77:1883", "SendingdLoop"); client.connect(); My Java-Application tells me that the connection has been refused (so there is no timeout): Could not establish connection (32103) - java.net.ConnectException: Connection **refused**: connect at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:75) at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:538) at java.lang.Thread.run(Thread.java:722) Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391) at java.net.Socket.connect(Socket.java:579) at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:66) I followed the official instructions to open the port: https://wiki.debian.org/iptables my entry looks like this: -A INPUT -p tcp -m tcp --dport 1883 -j ACCEPT When I check iptables, iptables -L ACCEPT tcp -- anywhere anywhere tcp dpt: 1883 I can see the rule is active. Is there anything else I have to configure?
"Is there anything else I have to configure?" Your router, perhaps. You really have not provided enough information to provide a definitive answer, all you've done is point out is not because of iptables...perhaps. Iptables rules are processed in order. If that was the last rule appended (-A) and is last in the list when you look at iptables -L, then it can be superseded by a preceding rule. E.g., if the list looks like: DROP everything ACCEPT everything Nothing will be accepted because everthing will be dropped before the second rule is processed (more exactly, the second rule will never be processed because everything will find a match in the first rule).
Socket Connection Refused (raspbian) but ports are open for connections
1,350,977,846,000
Using the terminal I was wondering if it would be possible to see a list of all the active firewalls on a particular system that I have shelled into. I want to be able to see which ports are active pertaining to each firewall, so that I can change the restrictions.
You could scan your localhost for open ports using a tool like nmap. nmap -v -sT localhost nmap can be built from source or installed from the repo of most (if not all) major distros.
How To See Which Ports Are Open On A Particular Firewall
1,350,977,846,000
Currently I'm updating my iptables rules using a bash script, where I call the command: iptables -F then I apply the rules. The problem being that I need to update the rules to gain access to port 80, then I drop everything, in a cron job every 10 minutes. So every 10 minutes I call iptables -F to delete old rules and open all ports (the thing I don't want). I want to not have to flush the rules every 10 minutes, just edit or update the existing rules.
If there are specific rules that need to be updated regularly, I would put them in a separate chain, calling that chain from INPUT in an appropriate slot iptables -N mychain # Create new chain "mychain" iptables -A INPUT mychain # Insert it into INPUT iptables -A INPUT …other rules… # Append other rules as before Now you can flush and add the frequently changing rules in mychain without affecting the rules in INPUT: iptables -F mychain iptables -A mychain …rule… iptables -A mychain …rule… … If you really want to have these added as a single entity as if it were in a transaction, you could create the chain, add your rules to that chain, and then insert that chain into INPUT, removing the previous instance immediately afterwards. You would probably want dynamic chain names for this. For example, chain="mychain_$(date +%s)" # One second granularity iptables -N "$chain" # Create the chain iptables -A "$chain" …rule… # and its rules iptables -A "$chain" …rule… iptables -A "$chain" …rule… … then old=$(iptables -L INPUT | awk '$1 ~ /^mychain_[0-9]+$/ {print $1; exit}') iptables -I INPUT 1 -j "$chain" # Add new chain in correct position if [ -n "$old" ] then iptables -D INPUT -j "$old" # Remove old chain iptables -X "$old" # Delete it fi On the other hand, if your requirement is to block or permit large numbers of IP addresses you would be better looking at an IP set.
How to update, instead of flush and re-write, iptables rules
1,350,977,846,000
I am trying to run the following nft commands: nft add table netdev filter nft -- add chain netdev filter input { type filter hook ingress device vlan100 priority -500 \; policy accept \; } nft add rule netdev filter input ip daddr 198.18.0.0/24 udp dport 1234 counter drop However, when I try to run the second command I keep getting this error: Error: Could not process rule: No such file or directory add chain netdev filter input { type filter hook ingress device vlan100 priority -500 ; policy accept ; } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This error is too general and not clear what it means. I checked to make sure table netdev filter was created. (It is) I tried in interactive mode by just supplying add chain netdev filter input { type filter hook ingress device vlan100 priority -500 ; policy accept ; }, and I get this error Error: Could not process rule: No such file or directory add chain netdev filter input { type filter hook ingress device vlan100 priority -500 ; policy accept ; } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Other suggested from this post that I need to "Enable Kernel Options" however its not clear how I do this? How do I enable Kernel options? I also read this post And Question2 on this post , but this post does not detail how to actually enable these options. Do I need to recompile Linux from source with these options enabled? If so, how does one accomplish this, can someone share a guide on how to do this please? I am running kernel version 5.4.0-91 on Ubuntu 20.04. I am not sure if I am missing a kernel option? I can see the following when running cat /boot/config-5.4.0-91-generic | grep -i "Config_NF_\|Config_NETFILTER" CONFIG_NETFILTER=y CONFIG_NETFILTER_ADVANCED=y CONFIG_NETFILTER_INGRESS=y CONFIG_NETFILTER_NETLINK=m CONFIG_NETFILTER_FAMILY_BRIDGE=y CONFIG_NETFILTER_FAMILY_ARP=y CONFIG_NETFILTER_NETLINK_ACCT=m CONFIG_NETFILTER_NETLINK_QUEUE=m CONFIG_NETFILTER_NETLINK_LOG=m CONFIG_NETFILTER_NETLINK_OSF=m CONFIG_NF_CONNTRACK=m CONFIG_NF_LOG_COMMON=m CONFIG_NF_LOG_NETDEV=m CONFIG_NETFILTER_CONNCOUNT=m CONFIG_NF_CONNTRACK_MARK=y CONFIG_NF_CONNTRACK_SECMARK=y CONFIG_NF_CONNTRACK_ZONES=y # CONFIG_NF_CONNTRACK_PROCFS is not set CONFIG_NF_CONNTRACK_EVENTS=y CONFIG_NF_CONNTRACK_TIMEOUT=y CONFIG_NF_CONNTRACK_TIMESTAMP=y CONFIG_NF_CONNTRACK_LABELS=y CONFIG_NF_CT_PROTO_DCCP=y CONFIG_NF_CT_PROTO_GRE=y CONFIG_NF_CT_PROTO_SCTP=y CONFIG_NF_CT_PROTO_UDPLITE=y CONFIG_NF_CONNTRACK_AMANDA=m CONFIG_NF_CONNTRACK_FTP=m CONFIG_NF_CONNTRACK_H323=m CONFIG_NF_CONNTRACK_IRC=m CONFIG_NF_CONNTRACK_BROADCAST=m CONFIG_NF_CONNTRACK_NETBIOS_NS=m CONFIG_NF_CONNTRACK_SNMP=m CONFIG_NF_CONNTRACK_PPTP=m CONFIG_NF_CONNTRACK_SANE=m CONFIG_NF_CONNTRACK_SIP=m CONFIG_NF_CONNTRACK_TFTP=m CONFIG_NF_CT_NETLINK=m CONFIG_NF_CT_NETLINK_TIMEOUT=m CONFIG_NF_CT_NETLINK_HELPER=m CONFIG_NETFILTER_NETLINK_GLUE_CT=y CONFIG_NF_NAT=m CONFIG_NF_NAT_AMANDA=m CONFIG_NF_NAT_FTP=m CONFIG_NF_NAT_IRC=m CONFIG_NF_NAT_SIP=m CONFIG_NF_NAT_TFTP=m CONFIG_NF_NAT_REDIRECT=y CONFIG_NF_NAT_MASQUERADE=y CONFIG_NETFILTER_SYNPROXY=m CONFIG_NF_TABLES=m CONFIG_NF_TABLES_SET=m CONFIG_NF_TABLES_INET=y CONFIG_NF_TABLES_NETDEV=y CONFIG_NF_DUP_NETDEV=m CONFIG_NF_FLOW_TABLE_INET=m CONFIG_NF_FLOW_TABLE=m CONFIG_NETFILTER_XTABLES=m CONFIG_NETFILTER_XT_MARK=m CONFIG_NETFILTER_XT_CONNMARK=m CONFIG_NETFILTER_XT_SET=m CONFIG_NETFILTER_XT_TARGET_AUDIT=m CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m CONFIG_NETFILTER_XT_TARGET_CONNMARK=m CONFIG_NETFILTER_XT_TARGET_CONNSECMARK=m CONFIG_NETFILTER_XT_TARGET_CT=m CONFIG_NETFILTER_XT_TARGET_DSCP=m CONFIG_NETFILTER_XT_TARGET_HL=m CONFIG_NETFILTER_XT_TARGET_HMARK=m CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m CONFIG_NETFILTER_XT_TARGET_LED=m CONFIG_NETFILTER_XT_TARGET_LOG=m CONFIG_NETFILTER_XT_TARGET_MARK=m CONFIG_NETFILTER_XT_NAT=m CONFIG_NETFILTER_XT_TARGET_NETMAP=m CONFIG_NETFILTER_XT_TARGET_NFLOG=m CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m # CONFIG_NETFILTER_XT_TARGET_NOTRACK is not set CONFIG_NETFILTER_XT_TARGET_RATEEST=m CONFIG_NETFILTER_XT_TARGET_REDIRECT=m CONFIG_NETFILTER_XT_TARGET_MASQUERADE=m CONFIG_NETFILTER_XT_TARGET_TEE=m CONFIG_NETFILTER_XT_TARGET_TPROXY=m CONFIG_NETFILTER_XT_TARGET_TRACE=m CONFIG_NETFILTER_XT_TARGET_SECMARK=m CONFIG_NETFILTER_XT_TARGET_TCPMSS=m CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m CONFIG_NETFILTER_XT_MATCH_BPF=m CONFIG_NETFILTER_XT_MATCH_CGROUP=m CONFIG_NETFILTER_XT_MATCH_CLUSTER=m CONFIG_NETFILTER_XT_MATCH_COMMENT=m CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m CONFIG_NETFILTER_XT_MATCH_CONNMARK=m CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m CONFIG_NETFILTER_XT_MATCH_CPU=m CONFIG_NETFILTER_XT_MATCH_DCCP=m CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m CONFIG_NETFILTER_XT_MATCH_DSCP=m CONFIG_NETFILTER_XT_MATCH_ECN=m CONFIG_NETFILTER_XT_MATCH_ESP=m CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m CONFIG_NETFILTER_XT_MATCH_HELPER=m CONFIG_NETFILTER_XT_MATCH_HL=m CONFIG_NETFILTER_XT_MATCH_IPCOMP=m CONFIG_NETFILTER_XT_MATCH_IPRANGE=m CONFIG_NETFILTER_XT_MATCH_IPVS=m CONFIG_NETFILTER_XT_MATCH_L2TP=m CONFIG_NETFILTER_XT_MATCH_LENGTH=m CONFIG_NETFILTER_XT_MATCH_LIMIT=m CONFIG_NETFILTER_XT_MATCH_MAC=m CONFIG_NETFILTER_XT_MATCH_MARK=m CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m CONFIG_NETFILTER_XT_MATCH_NFACCT=m CONFIG_NETFILTER_XT_MATCH_OSF=m CONFIG_NETFILTER_XT_MATCH_OWNER=m CONFIG_NETFILTER_XT_MATCH_POLICY=m CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m CONFIG_NETFILTER_XT_MATCH_QUOTA=m CONFIG_NETFILTER_XT_MATCH_RATEEST=m CONFIG_NETFILTER_XT_MATCH_REALM=m CONFIG_NETFILTER_XT_MATCH_RECENT=m CONFIG_NETFILTER_XT_MATCH_SCTP=m CONFIG_NETFILTER_XT_MATCH_SOCKET=m CONFIG_NETFILTER_XT_MATCH_STATE=m CONFIG_NETFILTER_XT_MATCH_STATISTIC=m CONFIG_NETFILTER_XT_MATCH_STRING=m CONFIG_NETFILTER_XT_MATCH_TCPMSS=m CONFIG_NETFILTER_XT_MATCH_TIME=m CONFIG_NETFILTER_XT_MATCH_U32=m CONFIG_NF_DEFRAG_IPV4=m CONFIG_NF_SOCKET_IPV4=m CONFIG_NF_TPROXY_IPV4=m CONFIG_NF_TABLES_IPV4=y CONFIG_NF_TABLES_ARP=y CONFIG_NF_FLOW_TABLE_IPV4=m CONFIG_NF_DUP_IPV4=m CONFIG_NF_LOG_ARP=m CONFIG_NF_LOG_IPV4=m CONFIG_NF_REJECT_IPV4=m CONFIG_NF_NAT_SNMP_BASIC=m CONFIG_NF_NAT_PPTP=m CONFIG_NF_NAT_H323=m CONFIG_NF_SOCKET_IPV6=m CONFIG_NF_TPROXY_IPV6=m CONFIG_NF_TABLES_IPV6=y CONFIG_NF_FLOW_TABLE_IPV6=m CONFIG_NF_DUP_IPV6=m CONFIG_NF_REJECT_IPV6=m CONFIG_NF_LOG_IPV6=m CONFIG_NF_DEFRAG_IPV6=m CONFIG_NF_TABLES_BRIDGE=m CONFIG_NF_LOG_BRIDGE=m CONFIG_NF_CONNTRACK_BRIDGE=m Why can I not add the chain? What am I doing wrong? UPDATE: The problem was related to the interface name. I was following instructions from this post (step 6). I did not realize they created an interface with the name "vlan100". However after closer inspection from the author's github README.md (Found here) It shows they created "vlan100" earlier on in the context of the setup. The fix for myself was to apply the netdev chain to an existing network interface (primarily the one I was sending traffic to)
In the nftables wiki, the netdev family is described like this: The netdev family is different from the others in that it is used to create base chains attached to a single network interface. Such base chains see all network traffic on the specified interface, with no assumptions about L2 or L3 protocols. "No assumptions about L2 protocols" would probably mean that VLAN tags have not been processed yet at that point. That would seem to mean could attach netdev chains to physical network devices only, not to VLAN devices. Note: this is just my guess. But if it turns out to be correct, the error message would make sense: the vlan100 virtual network interface would not exist in the context of netdev nftables family, because it is not a physical network interface.
nftables refuses to add chain
1,350,977,846,000
We have RedHat 8 server. Firewalld is active. I need to connect to port 5050 from my lap top and from the second server, so I added it to the rules iptables -I INPUT -p tcp -m tcp --dport 5050 -j ACCEPT service iptables save When trying to connect from second server: telnet 10.244.176.1 5050 Trying 10.244.176.1... telnet: connect to address 10.244.176.1: No route to host When trying from my lap top telnet: Connecting To 10.244.176.1...Could not open connection to the host, on port 5050: Connect failed I can ping that IP from both sources. Also traceroute output is the following (from the second server level): traceroute 10.244.176.1 traceroute to 10.244.176.1 (10.244.176.1), 30 hops max, 60 byte packets 1 10.244.176.1 (10.244.176.1) 0.287 ms !X 0.293 ms !X 0.286 ms !X What can I do?
If you're using firewalld, why not add the rule to firewalld instead of iptables? You can list the different zones in your firewalld configuration like this: firewall-cmd --get-zones If you want to see the rule sets for all zones: firewall-cmd --list-all-zones If you want to see the rule sets for a specific zone: firewall-cmd --zone=$ZONE --list-all Where $ZONE is the name of one of your zones. This will allow the port in runtime: firewall-cmd --zone=$ZONE --add-port=5050/tcp To make the rule permanent: firewall-cmd --permanent --zone=$ZONE --add-port=5050/tcp So if you wanted to add the rule to just test out first for the public zone: firewall-cmd --zone=public --add-port=5050/tcp Then if that works and you wanted to make it permanent: firewall-cmd --permanent --zone=public --add-port=5050/tcp Alternatively if you wanted to use a GUI to do this you could launch: firewall-config and do the same thing via a GUI.
Firewall is active, added port to iptables but still cannot connect
1,350,977,846,000
Something is unclear to me about inbound traffic and firewalls. My first assumption is that a firewall - say for a home router - should block all inbound ports. If you don't block all inbound ports, then surely hackers on the Internet can send packets to the devices on your network? But if all inbound ports are blocked, how does any traffic get in? For example, my understanding is that a browser sets up a connection to a web server - talking to port 80 on the web server, and some randomly assigned port number on the browser/client end - say for example port 30222. Browser asks for a page, web server sends it back addressed to the clients ip address/port 30222. If the web server can send data to port 30222, then why couldn't any random hacker send data to port 30222? How does the firewall view this? Should it be configured to permit all inbound connections? I understand that there are stateful firewalls that examine the connection request from the client and can therefore selectively allow traffic on precisely that combination of client/port -> server/port - that make sense. In that context I can see you could block all inbound firewall ports on the home router because the home router is able to ensure traffic that it lets in is only between devices for a connection initiated internally - it is not possible in such context for a random hacker to send packets to a device on the internal network. BUT - I don't think all firewalls are stateful are they? What about non-stateful firewalls - do they require allowing all inbound traffic? So it is not clear to me if a home firewall should block all inbound ports or not. And if it does block all inbound ports, how does any data get in if it is not a stateful packet inspection firewall?
The term firewall is loosely defined. My answer to your question is that not all firewalls are stateful. However, I might use the term "packet filter firewall", to describe one type of stateless firewall. For a stateless firewall, there is still a lot of protection that can be achieved but not as much as a stateful firewall. For example, a stateless firewall could be told to let all packets go out to the Internet (e.g. your web browser packets going to the web server). But it would be configured to only allow packets inbound if they appeared to be part of an already established connection. For this we get into the details of how TCP/IP works. There are flags (SYN, SYN+ACK, ACK in case you wanted to look them up) in the TCP packet which indicate if a packet is an initiating packet or a response packet. The stateless firewall would only allow response packets back into your client browser. Could a bad guy on the Internet simply send a packet that looked like a response (i.e. had the response flag set) back to your client? Yes. However, it's unlikely that your client would accept that connection even if it got past the packet filter firewall. This is a very basic answer and I'm skipping over many details and scenarios but hopefully it provides the level of detail that you were looking for. In this above context, we are using the term "stateful" and "stateless" to describe what the firewall is keeping track of. Stateful means that once the first packet from your browser gets to the firewall, the firewall notes that a web connection is being activated and the firewall is then expecting the response packet from the web server. It keeps tracking information for the duration of the connection. In a "stateless" scenario, the firewall evaluates each packet as they pass through it but does not keep track of anything in between. The TCP/IP connection has "state" information inside of it (e.g. the flags) regardless of whether the firewall is keeping track of it or not.
How does inbound port blocking work on a firewall?
1,350,977,846,000
I'm trying to block only outbound connections to specific IP addresses, however I want to allow inbound connections from the same IP addresses. From what I understand about blocking outbound connections, they shouldn't block if an inbound connection has been made successfully. I basically set up rules like this: --append OUTPUT --jump DROP --destination x.x.x.x And to allow established connections: --append INPUT --in-interface eth0 --match state --state RELATED,ESTABLISHED --jump ACCEPT I want connections to be allowed when this IP address attempts to connect to the server, but when my server tries to make an outbound connection, it shouldn't be able to make it. I would like to block complete access for the server to make outbound connections to x.x.x.x. However when a user from that IP wishes to access the server they should be able to visit sites on certain ports.
You are nearly there with your attempted firewall rules. Here's what you need to allow inbound traffic from host 10.10.10.10 while stopping outbound traffic to that address: Allow inbound (presumably to any port) Allow outbound replies to established inbound connections Block remaining outbound traffic So, iptables -A INPUT --src 10.10.10.10 --jump ACCEPT iptables -A OUTPUT --match state --state RELATED,ESTABLISHED --jump ACCEPT iptables -A OUTPUT --dst 10.10.10.10 --jump DROP You don't really need the INPUT rule unless you have later rules reaching DENY/REJECT or your policy is set that way.
Iptables outbound block denies inbound
1,350,977,846,000
I'm trying to audit firewall rules on a host. This is typically pretty straightforward to do with nmap or a similar scanning tool. The problem is that I can only run the audit on the host itself. Normally, if you run a port scan with nmap against the current host, nmap will use the loopback interface. This is a problem because the firewalls on the hosts that I care about allow all traffic on the loopback interface: [my-host ~][I]% sudo iptables -vL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination [...snip...] 2364K 123M ACCEPT all -- lo any anywhere anywhere [...snip...] And consequently, when I scan the host, all ports appear to be allowed by the firewall: [my-host ~][I]% sudo nmap -sA my-host Starting Nmap 6.40 ( http://nmap.org ) at 2020-01-28 13:53 MST Nmap scan report for my-host (172.20.48.30) Host is up (0.000015s latency). rDNS record for 172.20.48.30: my-host All 1000 scanned ports on my-host (172.20.48.30) are unfiltered Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds So I tried specifying the interface to use, hoping to force the scan to route traffic through the host's normal network interface. But nmap can't find any open ports: [my-host ~][I]% sudo nmap -sA my-host -e ens192 -Pn Starting Nmap 6.40 ( http://nmap.org ) at 2020-01-28 13:54 MST Nmap done: 1 IP address (0 hosts up) scanned in 0.44 seconds However, I know that, in its firewall, the host allows at least port 22 from any other host on the same network. When I scan it from another host on the same network, that is what I see: [my-other-host ~][I]% sudo nmap -sA my-host -Pn Starting Nmap 6.40 ( http://nmap.org ) at 2020-01-28 13:55 MST Nmap scan report for my-host (172.20.48.30) Host is up (0.00021s latency). rDNS record for 172.20.48.30: my-host Not shown: 999 filtered ports PORT STATE SERVICE 22/tcp unfiltered ssh MAC Address: 00:50:56:A0:34:4D (VMware) Nmap done: 1 IP address (1 host up) scanned in 4.51 seconds So why can I not see these results when scanning my-host from itself? Is this due to the router configuration (which unfortunately I don't have access to), or am I making a mistake somewhere?
The problem is that the Linux routing tables always route traffic locally through the loopback interface and do not put it on the physical network if the local system has a network interface listening for the destination IP address. You can see the local routing table with ip route show table local - all packets matching a rule in the local routing table are looped back. Additionally, the local routing table is automatically maintained (rules are added/removed when bringing interfaces up/down) and cannot be manually altered. Therefore the nmap scanning packets will always end up on the loopback interface (and effectively miss the firewall) even when explicitly specifying the interface to bind to. The solution is to create a namespaced virtual network to run the scan from. A namespaced virtual network has its own virtual network interfaces and routing tables separate from other namespaced networks, including the root network namespace. This means that packets sent across namespaces appear to come from an external network and are not considered local packets. I followed the guide here to create a namespaced network. In the end, the script to create the network looked like this: test_source_ip='5.5.5.5' test_dest_ip='5.5.5.6' ip netns add testns ip netns exec testns ip link set dev lo up ip link add veth0 type veth peer name veth1 ip link set veth1 netns testns ip netns exec testns ifconfig veth1 ${test_source_ip}/24 up ifconfig veth0 ${test_dest_ip}/24 up testns is the name of the virtual namespaced network; you can call yours whatever you want. The source IP and destination IP can be any arbitrary IP address, which means you can spoof arbitrary source IP addresses when running a scan, which is quite helpful. Be careful, however, not to mask any real IP addresses that the system might want to communicate with. Finally, running your nmap scan is a matter of ensuring that it runs from within the namespaced network. You also need to scan the IP address of the paired virtual ethernet adapter in the root namespace (NOT the system's actual IP address): ip netns exec testns nmap -sA -n ${test_dest_ip} And you should see your scan run as if it actually came from 5.5.5.5. [vagrant@2d33f851-838c-4 ~]$ sudo ip netns exec testns nmap -sA -n 5.5.5.6 Starting Nmap 6.40 ( http://nmap.org ) at 2020-02-05 17:41 MST Nmap scan report for 5.5.5.6 Host is up (0.000066s latency). Not shown: 997 filtered ports PORT STATE SERVICE 22/tcp unfiltered ssh 1234/tcp unfiltered hotline 5678/tcp unfiltered rrac MAC Address: FE:64:90:7E:51:81 (Unknown) Nmap done: 1 IP address (1 host up) scanned in 5.13 seconds [vagrant@2d33f851-838c-4 ~]$
How can I port scan a host from itself without using the loopback interface?
1,350,977,846,000
I've added a new service in my CentOS server using the following command: firewall-cmd --permanent --add-service=wiremock sudo firewall-cmd --reload then I've removed it through firewall-cmd --permanent --remove-service=wiremock sudo firewall-cmd --reload when I do firewall-cmd --get-services, I can still the service enumerated in the returned list. Any idea?
The man page is a bit vague about these options, but the --add-service and --remove-service options are actually used to enable or disable a specific firewalld service. See the Fedora Wiki page for clearer examples. On the other hand, the --get-services option returns a list of firewalld services predefined on that particular system. Enabling/disabling a service has no effect on this list, because it is based on the discovery of XML files that define these services. In your case, you should find a service definition file named wiremock.xml (or similar) under the /usr/lib/firewalld directory or /etc/firewalld. Removing this specific XML file will unlist the service. If you have not added this service definition yourself, you should first check where it came from. If it was shipped as part of a package, reinstalling/updating that package will restore the file.
Cannot remove a firewall service previously created
1,350,977,846,000
On remote server, the iscsi service listens on port 3260. What determines the local port used on the iscsi client ? I am using the open-iscsi package, and the /usr/sbin/iscsid as client. In the example below, can see with netstat -ptn, that my client (1.2.3.4) listens on port 38770: tcp 0 0 1.2.3.4:38770 1.2.3.5:3260 ESTABLISHED 29161/iscsid Is this port completely random, or can it be specified somewhere on the client side ? I need to know this port in advance, so that I can configure the firewall.
Is this port completely random, or can it be specified somewhere on the client side ? All TCP/UDP connections work by picking a random port for the client (while the server has a well-known port). You don't get to specify the port, the OS picks it for you (though possibly the client can work around that, if you add enough code to it). I need to know this port in advance, so that I can configure the firewall. No, you don't. You tell the firewall the server port, and then you tell the connection tracker of your firewall that established connections to that port should be passed through. This will deal with the random port on the client side.
iscsid: iscsi client local port
1,350,977,846,000
I have a server with a docker and a UFW firewall (I know it might have conflit because docker open some port despite UFW rules) but: When I telnet this server from outside on a random closed port, Telnet stay in "Trying..." instead of sending a "Refused connection" If I go to the server and do the same with telnet 127.0.0.1 7777 I have the "Refused connection" Any idea ?
Many firewalls will "stealth" a port rather than actually "close" it. What this means is, rather than affirmatively sending back a "Connection Refused", it will instead waste the client's time making it think it will get a response back before its own timeout. In this way, the thinking goes, a potential attacker's port scan is less utile because it's impossible to tell which ports are actually closed and which may simply have slow or currently-nonresponsive services behind them. It also means a crafty attacker can't make the target waste its time sending a ton of "sorry, we're closed" packets in lieu of nothing at all.
Telnet to a closed port does not reply connnection refused
1,350,977,846,000
I'm trying to install naxsi on ubuntu 18.x. After googling and trying I found: nginx-naxsi is no more available for ubuntu, so you have to compile by yourserlf. Well to understand which module and setup I've installed apt install nginx-extras then nginx -V and I found this: nginx version: nginx/1.14.0 (Ubuntu) built with OpenSSL 1.1.0g 2 Nov 2017 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-mcUg8N/nginx-1.14.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' \ --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' \ --prefix=/usr/share/nginx \ --conf-path=/etc/nginx/nginx.conf \ --http-log-path=/var/log/nginx/access.log \ --error-log-path=/var/log/nginx/error.log \ --lock-path=/var/lock/nginx.lock \ --pid-path=/run/nginx.pid \ --modules-path=/usr/lib/nginx/modules \ --http-client-body-temp-path=/var/lib/nginx/body \ --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \ --http-proxy-temp-path=/var/lib/nginx/proxy \ --http-scgi-temp-path=/var/lib/nginx/scgi \ --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \ --with-debug \ --with-pcre-jit \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_realip_module \ --with-http_auth_request_module \ --with-http_v2_module \ --with-http_dav_module \ --with-http_slice_module \ --with-threads \ --with-http_addition_module \ --with-http_flv_module \ --with-http_geoip_module=dynamic \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_image_filter_module=dynamic \ --with-http_mp4_module \ --with-http_perl_module=dynamic \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_sub_module \ --with-http_xslt_module=dynamic \ --with-mail=dynamic \ --with-mail_ssl_module \ --with-stream=dynamic \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-headers-more-filter \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-auth-pam \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-cache-purge \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-dav-ext \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-ndk \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-echo \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-fancyindex \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/nchan \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-lua \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/rtmp \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-uploadprogress \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-upstream-fair \ --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-subs-filter so I assembled into this batch #!/usr/bin/env bash apt-get install -y libpcre3 libpcre3-dev libssl-dev unzip make \ libgoogle-perftools-dev google-perftools jq gcc mkdir /tmp/ngxbuild cd /tmp/ngxbuild latestNginx=$(curl -s http://hg.nginx.org/nginx/tags | grep "^ *release-" | head -1 | cut -c 9-) latestNaxsi=$(curl -s https://api.github.com/repos/nbs-system/naxsi/releases | jq -r .[].tag_name | grep -v rc | head -1) wget -q http://nginx.org/download/nginx-${latestNginx}.tar.gz wget -q https://github.com/nbs-system/naxsi/archive/${latestNaxsi}.tar.gz tar xzf nginx-${latestNginx}.tar.gz tar xzf ${latestNaxsi}.tar.gz cd nginx* ./configure --conf-path=/etc/nginx/nginx.conf \ --add-module=../naxsi-${latestNaxsi}/naxsi_src/ \ --with-cc-opt='-g -O2 -fdebug-prefix-map=/b (... see up for complete list of parameters) ... --add-dynamic-module=/build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-subs-filter make -j 4 make install but errors arise... --with-debug : unknow command --with-pcre-jit : unknow command ... --with-http_ssl_module : unknow command and module like /build/nginx-mcUg8N/nginx-1.14.0/debian/modules/http-subs-filter is from library or I've to download so I just want to install nginx - naxsi on ubuntu 18.x, any solution??
Your options when compiling are being interpreted as commands, which is why it is saying command not found. Most likely you are not escaping a newline, so the shell thinks the option on the next line is a command to run. This newline in your example is not escaped properly: ./configure --conf-path=/etc/nginx/nginx.conf \ --add-module=../naxsi-${latestNaxsi}/naxsi_src/ \ --with-cc-opt='-g -O2 -fdebug-prefix-map=/b
compile nginx and naxsi on ubuntu 18.x
1,350,977,846,000
I have installed ejabberd on a new installation of Ubuntu 16.04 on digitalocean cloud and am able to connect to it from pidgin from my local machine without configuring any firewall rules. Curious to see the ports open I did nmap <ip_address> PORT STATE SERVICE 22/tcp open ssh 5222/tcp open xmpp-client 5269/tcp open xmpp-server 5280/tcp open xmpp-bosh However, my ufw status is inactive and sudo iptables -S -P INPUT ACCEPT -P FORWARD ACCEPT -P OUTPUT ACCEPT is empty As suggested here I listed each of the tables contents using sudo iptables -vL -t <table_name> for each of filter, nat, mangle, raw, security all showing empty outputs. I would like to know if there is some other way in which firewall rules are configured and displayed.
Your misunderstanding is this: If there is no configuration for Netfilter (iptables) then everything is allowed. The default policy for all chains is ACCEPT.
Ubuntu ports open but iptables rules are empty
1,350,977,846,000
I opened up port 8887 on a server that had it disabled using ufw allow 8887/tcp. I'm not trying to close it again. I used ufw status numbered to get a list of rules and then ufw delete <NUMBER>. The problem is that I can still see the web portal on port 8887 when I'm expecting it to be closed. When I run ufw status I get back: To Action From -- ------ ---- 22 LIMIT Anywhere 2376/tcp ALLOW Anywhere 8140/tcp ALLOW Anywhere 32793/tcp ALLOW Anywhere 9000/tcp ALLOW Anywhere 8887 REJECT Anywhere 8887/tcp REJECT Anywhere 22 (v6) LIMIT Anywhere (v6) 2376/tcp (v6) ALLOW Anywhere (v6) 32793/tcp (v6) ALLOW Anywhere (v6) 9000/tcp (v6) ALLOW Anywhere (v6) 8887 (v6) REJECT Anywhere (v6) 8887/tcp (v6) REJECT Anywhere (v6) How can I make sure no one can access port 8887?
This might have been caused by the fact that I was using a pre-configured droplet from Digital Ocean labeled Ubuntu 16.04 with Docker pre-installed. One of the aspects setup was firewall which allows 2 ports needed by Docker Swarm and 22 for ssh. I'm thinking when I tried to setup my own firewall settings on the node it some how conflicted with their setup. I went to the node configuration on the Digital Ocean GUI and was able to add Firewall settings to accomplish what I was looking for.
UFW Firewall not working? [closed]
1,350,977,846,000
I get unintuitive results from "nmap -A " which I want to clarify. Setup: sshd (ssh deamon service) is successfully running. postfix is installed and so smpt service is running. However, it only configured to send mail, not to receive. apache not installed, iptables empty, ufw not installed. From this primary nmap documentation source: "Closed ports have no application listening on them" The Question: Is it possible that some instances of "filtered" results also simply have no application listening on them? Or does "filtered" always mean there is some other reason? (If it's the latter, I would like to find out what that other reason is, which is why I am asking.) nmap -A xxxxxx.com Starting Nmap 7.01 ( https://nmap.org ) at 2018-01-21 18:13 PST Nmap scan report for xxxxxx.com (45.**.***.***) Host is up (0.058s latency). rDNS record for 45.**.***.***: li****-***.members.linode.com Not shown: 995 closed ports PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 **** (RSA) |_ 256 **** (ECDSA) 25/tcp filtered smtp 135/tcp filtered msrpc 139/tcp filtered netbios-ssn 445/tcp filtered microsoft-ds Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel sudo lsof -i -n COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd 3396 root 3u IPv4 15205 0t0 TCP *:ssh (LISTEN) sshd 3396 root 4u IPv6 15214 0t0 TCP *:ssh (LISTEN) master 4988 root 12u IPv4 19670 0t0 TCP 127.0.0.1:smtp (LISTEN) master 4988 root 13u IPv6 19671 0t0 TCP [::1]:smtp (LISTEN) sshd 5582 root 3u IPv4 30352 0t0 TCP **.**.***.***:ssh->**.**.***.***:54224 (ESTABLISHED) sshd 5602 izxzxzn 3u IPv4 30352 0t0 TCP **.**.***.***:ssh->**.**.***.***:54224 (ESTABLISHED) sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
These are common ports blocked by internet service providers. It is impossible to tell if that is your issue from the information provided but 25 is often blocked to limit open spam relays. 135, 139 and 445 are often blocked to protect customers with unintentionally open file shares which used to be very common. In the case of my home provider, these ports are blocked by default but can be turned off in the customer interface. If this is a scan over the internet (by the looks of the .com in your nmap command it likely is) then there is almost certainly an ISP blocking access to those ports.
nmap "filtered" results on a pretty naked server - could "filtered" just mean "silence"?
1,350,977,846,000
So I'm trying to get Vuurmuur installed on a headless linux box that I've been using as a home router. So far, I've been using iptables but wanted to switch to using something more convenient/easier to use. SERVER SETUP I'm running: Ubuntu 16.04.3 LTS Xenial 4.4.0-97-generic #120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux VUURMUUR SETUP Vuurmuur doesn't have a debian package maintainer so I added this entry to my apt sources: deb ftp://ftp.vuurmuur.org/ubuntu/ raring main Do an apt-get update, install vuurmuur and things look ok BUT when I try to run vuurmuur this happens: # vuurmuur Error: checking for iptables-capabilities failed. Please see error.log. I checked the documentation here: https://www.vuurmuur.org/trac/wiki/Faq and that suggests that iptables or conntrack is not setup correctly For completeness, this is the error in the error log: 01/04/2018 13:57:18 : PID 1866 : vuurmuur : Error (-1): no connection tracking support in the kernel (in: check_iptcaps:402). I did a lsmod for iptables and conntrack and they both seem to be there: # lsmod | egrep "iptable|conntr" nf_conntrack_netlink 40960 0 nfnetlink 16384 2 nf_conntrack_netlink,nfnetlink_queue iptable_mangle 16384 0 xt_conntrack 16384 2 iptable_filter 16384 1 iptable_nat 16384 1 nf_conntrack_ipv4 16384 3 nf_defrag_ipv4 16384 1 nf_conntrack_ipv4 nf_nat_ipv4 16384 1 iptable_nat nf_conntrack 106496 9 xt_helper,nf_nat,xt_state,nf_nat_ipv4,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_netlink,xt_connmark,nf_conntrack_ipv4 ip_tables 24576 3 iptable_filter,iptable_mangle,iptable_nat x_tables 36864 20 xt_mark,xt_helper,xt_length,ip_tables,xt_tcpudp,ipt_MASQUERADE,xt_NFQUEUE,xt_limit,xt_state,xt_conntrack,xt_LOG,xt_mac,xt_nat,iptable_filter,xt_CLASSIFY,xt_TCPMSS,xt_connmark,ipt_REJECT,xt_REDIRECT,iptable_mangle WHAT AM I MISSING? I've seen some other posts that the way conntrack is enabled has changed in the past so I'm wondering if between Raring and Xenial, the method to check for iptables/conntrack changed but vuurmuur hasn't been updated yet. Thanks, Alex
So turns out their are two options: Option 1 Run the vuurmuur command with the below option: -t Option 2 (what I did) Use the 0.8rc5 version from the Vuurmuur website and I was able to start Vuurmuur.
How to resolve "no connection tracking support in the kernel" in Vuurmuur?
1,350,977,846,000
I want to block the user to start the firewall on Linux machines so I want to use mask on servers as the following: systemctl mask firewalld regarding that, I have few questions. I see that when mask the firewall service its creates a symbolic link of the firewall.service to /dev/null, thus disabling the service. So where is the location of the service that point to /dev/null (Path of the service that point to /dev/null)? second Masking the firewall is nice option to block users to start the firewall service, but as all know user can do unmask and then start the service. Any advice on if we have other strong option from mask?
As I understand the question, the users you are talking about have root access (since they can unmask a service). In this case there's nothing you can do. If you want your users not to enable a service, don't give them privileged access. About your first point, the firewalld service is defined in /usr/lib/systemd/system/firewalld.service.
linux redhat 7 ( or centos 7 ) + firewalld mask the firewall
1,350,977,846,000
What is the elegant way to verify if firewall is stop/inactive on redhat 7 machines? example: we stop the firewall: systemctl status firewalld.service and my approach to verify the firewall status is like this: systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) so in my bash script I do the following in order to check if firewall is stopped/inactive if [[ ` systemctl status firewalld.service | grep Active | awk '{print $2}' ` = inactive ]] then firewall_status=inactive else firewall_status=active fi but to check the results like this way is little clumsy.
RHEL 7 introduces a command firewall-cmd to work with firewall. But the catch is it requires root access. If you are running your script as root, then you can use the following code: if [[ `firewall-cmd --state` = running ]] then firewall_status=active else firewall_status=inactive fi But if you are not running your script as root, then, unfortunately, yours is the only way to do it.
how to check if firewall is stopped on redhat 7
1,350,977,846,000
I am trying to allow an IPv6 address connect to a certain IP on my server but not the others. The following is not working with ip6tables but it does work with just plain iptables. When I remove -d xx.xx.xx.77 from the ip6tables command it will work however, that will allow this ip6 address to connect to any IP on the box which I don't want. ip6tables -I INPUT -d xx.xx.xx.77 -i enp2s0f0 -p tcp -m multiport --dports http,https -s 2400:cb00::/32 -j ACCEPT ip6tables v1.6.0: host/network `xx.xx.xx.77' not found man ip6tables shows the following for -d and -s: [!] -s, --source address[/mask][,...] Source specification. Address can be either a network name, a hostname, a network IP address (with /mask), or a plain IP address. Hostnames will be resolved once only, before the rule is submitted to the kernel. Please note that specifying any name to be resolved with a remote query such as DNS is a really bad idea. The mask can be either an ipv4 network mask (for iptables) or a plain number, specifying the number of 1's at the left side of the network mask. Thus, an iptables mask of 24 is equivalent to 255.255.255.0. A "!" argument before the address specification inverts the sense of the address. The flag --src is an alias for this option. Multiple addresses can be specified, but this will expand to multiple rules (when adding with -A), or will cause multiple rules to be deleted (with -D). [!] -d, --destination address[/mask][,...] Destination specification. See the description of the -s (source) flag for a detailed description of the syntax. The flag --dst is an alias for this option.
IPv6 can not connect to an IPv4. in ip6tables everything needs to be ipv6
ip6tables will not accept -d destination but iptables will
1,350,977,846,000
I know I can use iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT in order to limit the acceptance of tcp syn packets. So if the tcp synpackets doesn't cross this rate, they will jump to ACCEPT. Is there a way to write this rule in the opposite direction? I want to write rules as following: If ok (doesn't cross the rate), continue down. Else drop <-- (1) ??? iptables -A INPUT -j OTHER_CHAIN_STUFF Is there a way to write (1) ? I tried iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j DROP but it works as: Drop until you reach the rate, then, when you pass the rate limit don't just to DROP no more, so it continue down - this is not what I want. Is there a way to write what I look for? Something like: iptables -A INPUT -p tcp --syn ! -m limit --limit 1/s -j DROP (pay attention to the !)
I just realised a simple solution: iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT iptables -A INPUT -p tcp --syn -j DROP Continue to do whatever I want
Using iptables '-m limit' in the opposite direction
1,350,977,846,000
Objective Given the following interfaces on a Raspberry Pi: eth0 (192.168.0.0/24) - Private network (i.e. NAT) wlan0 (192.168.10.0/24) - Public network with Internet access (i.e. LAN) tun0 (VPN) - VPN connection Build a firewall that achieves the following: Deny ALL inbound traffic to: wlan0, tun0 (block incoming connections) Route ALL outbound traffic from eth0 to tun0 (block "lateral" connections; i.e. no LAN access) If tun0 is down, DO NOT allow eth0 to use wlan0 instead (i.e. VPN killswitch) Mainstream Example I've seen numerous "VPN killswitch" examples at this point with UFW and they all share a common configuration: # Defaults ufw default deny outgoing ufw default deny incoming # Allow local over ethernet (without VPN) sudo ufw allow out to 192.168.0.0/24 # Allow out to LAN sudo ufw allow in to 192.168.0.0/24 # Allow in to LAN # Allow outgoing over ethernet to VPN sudo ufw allow out to [VPN] port 1194 proto udp # Allow outgoing over tun0 sudo ufw allow out on tun0 # Allow out over VPN Sources: https://forums.whirlpool.net.au/archive/2561726 https://www.reddit.com/r/VPN/comments/4ik46m/vpn_killswitch_setup_using_ufw/ https://www.youtube.com/watch?v=x9fb2UAWkBE https://github.com/andreisid/bash/blob/master/killswitch.sh My NAT Example (Alternative) Granted, in my application, I have an intermediate device (Raspberry Pi) in play that acts as a router, firewall, DNS & DHCP server, and VPN client so it is a slightly different setup. However, it would seem that the NAT table (/etc/ufw/before.rules) handles the ufw allow out/in to 192.168.0.0/24 statements and pretty much routes all outbound traffic coming from eth0 to tun0 (second objective item) as-is: # NAT table to "forward" private network to VPN tunnel *nat :POSTROUTING ACCEPT [0:0] -A POSTROUTING -s 192.168.0.0/24 -o tun0 -j MASQUERADE COMMIT This should "forward" anything coming from the private network (eth0) into the VPN tunnel (tun0), correct? Or do I need FORWARD clauses in here as well? After that, I'm not sure at this point if there is anything else I would need to configure, such as: # Set defaults (also see /etc/default/ufw) sudo ufw default deny incoming sudo ufw default deny outgoing # Allow incoming requests to DNS/DHCP services (UDP) on eth0 interface only (i.e. Private Network -> Pi:43,67/udp) sudo ufw allow in on eth0 from any to any port 53,67 proto udp # Allow incoming requests to SSH service (TCP) on eth0 interface only (i.e. Private Network -> Pi:22/tcp) sudo ufw allow in on eth0 from any to any port 22 proto tcp # Allow outbound on wlan0 interface for VPN traffic only (i.e. Pi -> LAN:1194) sudo ufw allow out on wlan0 from any to any port 1194 proto udp # Allow all outbound traffic on eth0 (i.e. Pi -> Private Network) sudo ufw allow out on eth0 # Allow all outbound traffic on VPN tunnel only (i.e. Pi -> VPN) sudo ufw allow out on tun0 In the tests I've done (traceroute, ping, etc.) with the NAT table alone, I can see my outbound Internet connection stops at the Raspberry Pi when I disconnect the VPN. However, what I'm still trying to confirm is whether this covers all possible leak scenarios (i.e. DNS, etc.). Note: I am also using dnsmasq so the Raspberry Pi is also the DNS server issued by the DHCP server to clients on the private network. I wonder if all I need to do is either configure dnsmasq to forward DNS queries through tun0 only (if that's even possible), or settle for forwarding onto public DNS instead (i.e. 8.8.8.8, 8.8.4.4). Also, as of right now, this setup blocks my outbound connections still, but issuing a sudo ufw allow out on wlan0 restores that connection (with VPN killswitch still in effect). So I feel like I'm close and maybe just a couple more rules off. Would greatly appreciate someone taking the time to look over these details and provide their feedback!
So I think I'm going to leave this answer up as I believe I may have just figured out the missing piece (thanks to /var/log/ufw.log) unless someone else sees otherwise: # Allow DNS queries # [UFW BLOCK] IN= OUT=wlan0 SRC=192.168.10.x DST=192.168.10.1 LEN=66 TOS=0x00 PREC=0x00 TTL=64 ID=50892 DF PROTO=UDP SPT=22617 DPT=53 LEN=46 sudo ufw allow out on wlan0 from any to any port 53 proto udp So my current ruleset looks like this now (note the default outgoing): Status: active Logging: on (low) Default: deny (incoming), deny (outgoing) New profiles: skip To Action From -- ------ ---- 53,67/udp on eth0 ALLOW IN Anywhere 22/tcp on eth0 ALLOW IN Anywhere 1194/udp ALLOW OUT Anywhere on wlan0 Anywhere ALLOW OUT Anywhere on eth0 Anywhere ALLOW OUT Anywhere on tun0 53/udp ALLOW OUT Anywhere on wlan0 Commands: # Allow incoming requests to DNS/DHCP services (UDP) on eth0 interface only (i.e. Private Network -> Pi:43,67/udp) sudo ufw allow in on eth0 from any to any port 53,67 proto udp # Allow incoming requests to SSH service (TCP) on eth0 interface only (i.e. Private Network -> Pi:22/tcp) sudo ufw allow in on eth0 from any to any port 22 proto tcp # Allow outbound on wlan0 interface for DNS and VPN traffic only (i.e. Pi -> LAN:1194) sudo ufw allow out on wlan0 from any to any port 53,1194 proto udp # Allow all outbound traffic on eth0 (i.e. Pi -> Private Network) sudo ufw allow out on eth0 # Allow all outbound traffic on VPN tunnel only (i.e. Pi -> VPN) sudo ufw allow out on tun0 # Set defaults (also see /etc/default/ufw) sudo ufw default deny incoming sudo ufw default deny outgoing This is also combined with my NAT table entry in /etc/ufw/before.rules mentioned in the original post for handling eth0 -> tun0 "routing." And finally, my /etc/dnsmasq.conf contains the following single server entry: # Force VPN by selecting public DNS server=8.8.8.8 # Do not read from /etc/resolv.conf and friends for system DNS no-resolv # Do not poll /etc/resolv.conf and friends for system DNS no-poll Doing a traceroute confirms requests going out to 8.8.8.8 is over the VPN and by configuration (DHCP implied), the client will default to the Pi for its DNS which in turn uses this configuration. That's a wrap!
A better VPN killswitch using UFW with NAT table?
1,440,610,426,000
I have the desktop-server Debian Jessie machine running for testing purposes just for 19 hours now. I have already set a few rules as you can see above. But I am not really into networking. So it needs some revision. Here is my iptables -L -v: Chain INPUT (policy DROP 1429 packets, 233K bytes) pkts bytes target prot opt in out source destination 1360 61482 DROP all -- any any anywhere anywhere ctstate INVALID 25079 2528K DROP icmp -- any any anywhere anywhere 15 480 DROP igmp -- any any anywhere anywhere 14353 7379K ACCEPT all -- lo any anywhere anywhere 5848K 1157M ACCEPT all -- any any anywhere anywhere ctstate RELATED,ESTABLISHED 1632 86441 ACCEPT tcp -- eth0 any anywhere anywhere tcp dpt:8333 9 472 ACCEPT tcp -- eth0 any anywhere anywhere tcp dpt:33211 13801 804K ACCEPT tcp -- eth0 any anywhere anywhere tcp dpt:56874 58386 5659K ACCEPT udp -- eth0 any anywhere anywhere udp dpt:56874 0 0 ACCEPT tcp -- eth0 any anywhere anywhere tcp dpt:63547 0 0 ACCEPT tcp -- eth0 any anywhere anywhere tcp dpt:https How can I drop all other incoming protocols than the ones I need, like HTTP(S), as the machine will serve mainly as a web server? When I run Etherape I see lots of protocols trying to connect through (or may have already penetrated) my firewall.
The above iptables config will only let TCP and UDP packets get past the firewall (unless they came from loopback). The default rule of the INPUT chain has been set to DROP, meaning that every packet that isn't explicitly ACCEPTed will be discarded. There should be no weird packets from loopback, so only TCP/UDP packets are allowed in. There is one major thing about protocols which should be cleared up: Network communication happens on many (actually seven) layers and each layer has it's own set of protocols. E.g., there are fundamental differences between the purpose of transport layer protocols (like TCP and UDP) and application layer protocols (like SMB). The scope of iptables is limited to the transport layer and below. Analysing packets for their application layer protocols requires deep packet inspection and is computationally much more expensive. One should also be careful not to confuse protocols and service names. Popular services have been assigned to specific ports. FTP services are typically available on port 21, while a web server will listen on port 80. This implies that the protocol in use will usually be FTP for traffic on port 21 and HTTP on port 80. However, traffic on any such port is in no way required to use the protocol associated with that service. Traffic on port 80 might as well be SSH or complete gibberish.
iptables - how to drop protocols [closed]
1,440,610,426,000
How do I allow certain IPs and block all other connection in iptables on AMAZON EC2?
You can accomplish this using UFW. Enable UFW and set default incoming to deny: $ sudo ufw enable && sudo ufw default deny incoming Then you can allow specific IP's with: $ sudo ufw allow from 192.168.1.10 to any This will allow IP-address 192.168.1.10 to any port on your firewall.
to allow certain ips and block all other connections on AMAZON EC2 ubuntu 12.04
1,440,610,426,000
I previously ACCEPTed all output traffic by default. Recently changed the policy to DENY output by default, only opening ports needed for server/application functionality. When I tried to mount a drive this morning, there was a timeout (the destination server is up). If I set the output policy to ACCEPT, I'm able to mount without issue. I've added the following rules to my firewall: Chain INPUT (policy DROP 166 packets, 49616 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp spt:137 state NEW,ESTABLISHED 628 48984 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp spt:137 state NEW,ESTABLISHED 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp spt:138 state NEW,ESTABLISHED 32 7244 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp spt:138 state NEW,ESTABLISHED 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp spt:139 state NEW,ESTABLISHED 0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp spt:139 state NEW,ESTABLISHED Chain OUTPUT (policy DROP 30 packets, 1800 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:137 state NEW,ESTABLISHED 0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:137 state NEW,ESTABLISHED 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:138 state NEW,ESTABLISHED 0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:138 state NEW,ESTABLISHED 3 180 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:139 state NEW,ESTABLISHED 0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:139 state NEW,ESTABLISHED By temporarily setting output to ACCEPT, I generated some INPUT traffic on ports udp:137, udp:138. I see some OUPUT traffic on tcp:139. The second I change default output to DENY, I get timeouts again. Here's the /etc/fstab line: //example.com/shares/acoder /mnt/acoder cifs credentials=/etc/credfile,dom=example,uid=0,gid=0,file_mode=0600,dir_mode=0700 0 0 0 0 In the example above, //example.com/shares/acoder is a Windows server. Here's the relevant portion of /etc/services # grep -i NETBIOS /etc/services netbios-ns 137/tcp # NETBIOS Name Service netbios-ns 137/udp netbios-dgm 138/tcp # NETBIOS Datagram Service netbios-dgm 138/udp netbios-ssn 139/tcp # NETBIOS session service netbios-ssn 139/udp What other port(s) need to be open for mounting with cifs?
You also need port 445 and make sure that you also have incoming related/established traffic allowed. grep 445 /etc/services microsoft-ds 445/tcp # Microsoft Naked CIFS microsoft-ds 445/udp
mount times out with iptables --policy OUTPUT DROP
1,440,610,426,000
I want to isolate a host on my home intranet using iptables on my linux router. So say for instance, I have a host that has the IP of 10.0.1.50 and I want it to be able to talk to the rest of the Internet, but I don't want the router to allow it to talk to any other host in 10.0.1.0/24. However, I want to be able to allow hosts in 10.0.1.0/24 to connect to 10.0.1.50 on port 80 only as long as the connection isn't created on the host. I am doing this in case 10.0.1.50 is compromised, so it can't talk to the rest of my network.
You're most probably doing it wrong. Your router can't prevent 10.0.1.50 from talking to the rest of the 10.0.1.0/24 subnet, because they're in the same subnet. A packet from 10.0.1.50 to another host in this subnet will not pass through the router, so you can't filter it. What you need to do is to set up a separate subnet, let's say for example 192.168.0.0/24 and put 10.0.1.50 into that subnet, for example with the new IP 192.168.0.50. Then connect this subnet to a separate interface of your router, and configure this interface to an IP like 192.168.0.1. Then you can set up your routing rules as desired: Allow established and related connections Allow 10.0.1.0/24 to connect to the Internet Allow 192.168.0.0/24 to connect to the Internet Allow connections from 10.0.1.0/24 to 192.168.0.50:80 Deny everything else
Isolate a hosts networking with iptables
1,440,610,426,000
As you know, at least 3 types of NAT are used. Of course i need to two types of them.DNAT and SNAT. DNAT : hiding server behind NAT, SNAT : hiding your client behind NAT. Question: I read a quick tutorial of PF filrewall, but didn't distinguish DNAT and SNAT in PF Firewall. How can i define ruleset as DNAT and SNAT?
I've been using NAT for a long time and this the first time I've seen the terms DNAT and SNAT. I had to go look at Wikipedia. To help you, pay attention to Wikipedia when it says "This use of DNAT is also called port forwarding". I've only ever heard it called port forwarding. The keyword you'll want on your rules is "rdr-to". Wikipedia points out that SNAT is used to mean many different things. With what you said, I'm assuming you are using SNAT in the sense of Source NAT. What you are referring to as SNAT is what PF means when it uses the rule modifier "nat-to". I don't know which tutorial you might have used, but the definitive one is at http://home.nuug.no/~peter/pf/ by Peter Hansteen. He also recently released the "Book of PF", which I own and is quite good. PF can be confusing if you are coming from Cisco (or other) nomenclature. I know this because I got rather confused when going from PF to Cisco while taking a class.
PF and types of NAT(Network Address Translation)
1,440,610,426,000
-A INPUT -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT every Firewall rule usually starts with this. Q: Does it matter that is it RELATED,ESTABLISHED OR ESTABLISHED,RELATED?
No, it's simply a list of co-equal packet states. In this case, order does not matter.
EST/REL or REL/EST in iptables firewall scripts?
1,440,610,426,000
I would like to install apache, php and mysql on Ubuntu 22.04 toolbox which is running in a Fedora 39 desktop VM. I am following the steps instructions provided in this link, but is seems to have some problem trying to set the ports in the firewall; when I run ⬢[lab@toolbox lab]$ sudo ufw allow in "Apache" WARN: initcaps [Errno 2] iptables v1.8.7 (nf_tables): Could not fetch rule set generation id: Permission denied (you must be root) Besides, $ sudo ufw status outputs error: ⬢[lab@toolbox lab]$ sudo ufw status ERROR: problem running iptables: iptables v1.8.7 (nf_tables): Could not fetch rule set generation id: Permission denied (you must be root)
You are in toolbox (a container) which doesn't have its own networking stack. Since toolbox runs in host networking mode, it should inherit whatever firewall rules you set outside toolbox. Have you tried running sudo ufw allow in "Apache" outside toolbox?
Install apache, php and mysql on Ubuntu 22.04 toolbox
1,440,610,426,000
I will filter inbound traffic with iptables. I have 2 goals. a) Allow HTTPS inbound at port 443. b) Redirect port 443 to process listening port on 9443. Not sure about the processing of that 2 rules. Do I need to set my INPUT rule to ACCEPT inbound HTTPS to port 443 or 9443?7 Depends on if redirection is done before or after I think.
The PREROUTING chain in the nat table handles the redirection for you: iptables -t nat -I PREROUTING --protocol tcp --dport 443 --jump REDIRECT --to-port 9443 Then the INPUT chain (implicitly in the filter table) handles permitted traffic: iptables -I INPUT --protocol tcp --dport 9443 --jump ACCEPT Notice that the result is that the service listening on port 9443 will effectively accept traffic on both its true port 9443 and the alternative 443.
Iptables: order of redirect and input-filter
1,440,610,426,000
I rely on my specific service to load iptables rules at startup in my debian installation, this service calls iptables-restore my_rules.v4 ip6tables-restore my_rules.v6 and do some other scripts however I realized that there's a small delta of time where default rules are applied between the enabling of the interfaces and the applying of the fw rules, this could expose the machine to some risks. I've enabled the iptables-persistent service but I'm not sure it is loaded before the networking part being started. What is the best way to load my script before networking is online and available ? I heard of pre-up in interfaces but I have many interfaces so I'm not sure of what interface be put up first, and using pre-up on all interfaces would cause the script being run too many times instead of just one.
In Debian 12, iptables is by default a wrapper for the new nftables subsystem. The iptables-persistent package depends on package netfilter-persistent, which creates a service named netfilter-persistent.service which is aliased to both iptables.service and ip6tables.service. The netfilter-persistent.service is defined like this: systemctl cat netfilter-persistent.service # /lib/systemd/system/netfilter-persistent.service [Unit] Description=netfilter persistent configuration DefaultDependencies=no Wants=network-pre.target systemd-modules-load.service local-fs.target Before=network-pre.target shutdown.target After=systemd-modules-load.service local-fs.target Conflicts=shutdown.target Documentation=man:netfilter-persistent(8) [Service] Type=oneshot RemainAfterExit=yes ExecStart=/usr/sbin/netfilter-persistent start ExecStop=/usr/sbin/netfilter-persistent stop [Install] WantedBy=multi-user.target # /usr/lib/systemd/system/netfilter-persistent.service.d/iptables.conf [Install] Alias=iptables.service ip6tables.service Note DefaultDependencies=no, Wants=network-pre.target and Before=network-pre.target. These already ensure that the iptables/nftables rules are restored before any network interface gets configured, assuming that you use any of the expected ways to configure network interfaces. So the answer is, yes, iptables-persistent gets loaded before any network interfaces are started. If you want to make your own custom service for your iptables/nftables rules, you should set the dependencies of that service the same way netfilter-persistent.service does. See the documentation of network-pre.target on the systemd.special(7) man page (emphasis mine): network-pre.target This passive target unit may be pulled in by services that want to run before any network is set up, for example for the purpose of setting up a firewall. All network management software orders itself after this target, but does not pull it in. Also see Running Services After the Network Is Up for more information.
Load iptables or nftables rules as fast as possible during boot and before the network interfaces be put online
1,440,610,426,000
I'm dealing with a RHEL version 6.4 server's firewall setting and the goal is to allow remote device to connect tcp port 6162, regardless of the type of services. The iptables rules are shown below(iptables -L --line-numbers), and service iptables has been restarted. num target prot opt source destination 1 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED 2 ACCEPT icmp -- anywhere anywhere 3 ACCEPT all -- anywhere anywhere 4 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh 5 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:6160 6 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:patrol-coll Chain FORWARD (policy ACCEPT) num target prot opt source destination Chain OUTPUT (policy ACCEPT) num target prot opt source destination Also, I did set the port I want in sytem-config-firewall, as shown figure below. The strange thing is: No matter how I set the firewall/iptable, the port 6162 just couldn't be opened. It has been tested with telnet client of windows/linux remote hosts that are residing in the same IP subnet of this RHEL 6.4 server. The connection to port 6162 is refused but others worked(such as port 6160). Tcp port 6162 seemed to be always "patrol-coll" but strictly speaking, I wanna allow any type of services to connect the 6162 port, not just "patrol-coll". Don't know whether the service type does impact on the connection... Can anyone please provide some hints to troubleshoot the OS-side problem of the connection please? Notes1: the output of netstat -tulpn is shown below. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2538/rpcbind tcp 0 0 192.9.110.1:1521 0.0.0.0:* LISTEN 4806/tnslsnr tcp 0 0 0.0.0.0:37426 0.0.0.0:* LISTEN 4493/ora_d000_SOGOE tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2917/sshd tcp 0 0 0.0.0.0:46775 0.0.0.0:* LISTEN 4686/ora_d000_SOGOL tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2737/cupsd tcp 0 0 127.0.0.1:10808 0.0.0.0:* LISTEN 3126/veeamservice tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3007/master tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 4046/sshd tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 2869/snmpd tcp 0 0 0.0.0.0:37449 0.0.0.0:* LISTEN 2657/rpc.statd tcp 0 0 :::111 :::* LISTEN 2538/rpcbind tcp 0 0 :::6160 :::* LISTEN 2886/veeamdeploymen tcp 0 0 :::40976 :::* LISTEN 2657/rpc.statd tcp 0 0 :::22 :::* LISTEN 2917/sshd tcp 0 0 ::1:631 :::* LISTEN 2737/cupsd tcp 0 0 ::1:25 :::* LISTEN 3007/master tcp 0 0 ::1:6010 :::* LISTEN 4046/sshd udp 0 0 0.0.0.0:111 0.0.0.0:* 2538/rpcbind udp 0 0 127.0.0.1:2547 0.0.0.0:* 4495/ora_s000_SOGOE udp 0 0 0.0.0.0:631 0.0.0.0:* 2737/cupsd udp 0 0 0.0.0.0:1017 0.0.0.0:* 2538/rpcbind udp 0 0 127.0.0.1:13179 0.0.0.0:* 4660/ora_pmon_SOGOL udp 0 0 10.50.89.26:123 0.0.0.0:* 2925/ntpd udp 0 0 192.9.110.1:123 0.0.0.0:* 2925/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 2925/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 2925/ntpd udp 0 0 0.0.0.0:28426 0.0.0.0:* 4672/ora_lgwr_SOGOL udp 0 0 0.0.0.0:18843 0.0.0.0:* 2657/rpc.statd udp 0 0 0.0.0.0:161 0.0.0.0:* 2869/snmpd udp 0 0 127.0.0.1:22464 0.0.0.0:* 4688/ora_s000_SOGOL udp 0 0 0.0.0.0:9798 0.0.0.0:* 4479/ora_lgwr_SOGOE udp 0 0 0.0.0.0:713 0.0.0.0:* 2657/rpc.statd udp 0 0 127.0.0.1:48982 0.0.0.0:* 4467/ora_pmon_SOGOE udp 0 0 127.0.0.1:26208 0.0.0.0:* 4686/ora_d000_SOGOL udp 0 0 127.0.0.1:54112 0.0.0.0:* 4493/ora_d000_SOGOE udp 0 0 :::111 :::* 2538/rpcbind udp 0 0 :::1017 :::* 2538/rpcbind udp 0 0 fe80::20c:29ff:fe74:83b5:123 :::* 2925/ntpd udp 0 0 fe80::20c:29ff:fe74:83bf:123 :::* 2925/ntpd udp 0 0 ::1:123 :::* 2925/ntpd udp 0 0 :::123 :::* 2925/ntpd udp 0 0 :::46340 :::* 2657/rpc.statd```
Your port 6160 works because it seems to have a Veeam Installer Service running (process name is something like veeamdeploymen* according to your netstat -tulpn output). Because there is no service running on port 6162 yet, the port will not open, although you seem to have already have unblocked it in firewall settings. Although someone might say "open a port in a firewall", that is a bit of a misnomer: a firewall does not really open ports, instead it can block them so that a port cannot be accessed even if an application opens it. If you don't have any network services running, all network ports will be closed by the operating system alone, and a firewall cannot change that. By requiring you to effectively configure any legitimate network port access twice (once to activate the service itself, then to unblock it in firewall settings), a firewall minimizes the risk of accidentally allowing unintended access. A firewall cannot reliably determine which remote application or service is attempting to connect: even if there was a protocol to allow that, the remote system can always tell lies. The Service field is probably just a human-friendly label assigned for a specific port number, typically in /etc/services. Some firewall management solutions will also allow pre-defining groups of port numbers as "services", for ease of configuration. If you want to open the port temporarily for test purposes, the "netcat" utility (package name nc) can do it: To open port 6162 for an incoming TCP connections: nc -kl 6162 Or if you want to open the port for UDP packets: nc -kul 6162 Once the command is stopped (with a Ctrl+C or a kill command), the port will automatically close again as there will no longer be a process present to handle any incoming data. Any data sent to the port over the network connection will be emitted to standard output; if you don't want that, you can append >/dev/null to the nc command lines. Note: the port TCP/6162 is the default port for Veeam Data Mover, however the fact that your system indicates a service name of patrol-coll suggests some other software might (once have) be(en) configured to use that port. (Perhaps a statistics collector of BMC Patrol monitoring software?)
RHEL 6.4 basic firewall rule port 6162 does not take effect
1,440,610,426,000
In a FreeBSD 13.1 install, I enabled the IPFW firewall and set firewall_type="workstation" in /etc/rc.conf. This allows outgoing requests, while denying incoming requests. When I checked the firewall log at /var/log/security, I see this entry: Apr 5 12:34:56 mycomputer kernel: ipfw: 65500 Deny UDP 192.168.1.1:67 192.168.1.123:68 in via wlan0 It seems that the firewall is blocking UDP packets from the DHCP server (192.168.1.1). Would this cause issues when the DHCP lease expires?
"Would this cause issues when the DHCP lease expires?" Yes. DHCP uses UDP as its transport protocol. DHCP messages from a client to a server are sent to the 'DHCP server' port (67), and DHCP messages from a server to a client are sent to the 'DHCP client' port (68). Source: RFC 2131
What are the consequences of blocking incoming UDP port 68 on my computer?
1,440,610,426,000
I have configured the following s2s VPN (in pfSense) connection which is working in general. Unfortunately, I can connect (ping, netcat, ssh) only from client to the server, but not back. If I can ssh normally, it means that firewall is not the problem, right? Since packages are travelling in both directions? How to diagnose the problem with the means of command line tools? I made a mistake, I can't netcat backwards. But I can see ping traffic with packet capture on a client when pining it from server. Also, I did add explicit route route add -net 192.168.31.0/24 192.168.27.2 on a server. Here is what I see when dumping packets on client when pinging it (.31.1) or it's network counterpars (.31.155) from the server $ tcpdump -n -i ovpnc2 icmp tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on ovpnc2, link-type NULL (BSD loopback), capture size 262144 bytes 20:04:44.123925 IP 192.168.27.1 > 192.168.31.1: ICMP echo request, id 14862, seq 0, length 64 20:04:45.133435 IP 192.168.27.1 > 192.168.31.1: ICMP echo request, id 14862, seq 1, length 64 20:04:46.146100 IP 192.168.27.1 > 192.168.31.1: ICMP echo request, id 14862, seq 2, length 64 20:04:49.664935 IP 192.168.27.1 > 192.168.31.155: ICMP echo request, id 1295, seq 0, length 64 20:04:50.663422 IP 192.168.27.1 > 192.168.31.155: ICMP echo request, id 1295, seq 1, length 64 20:04:51.679393 IP 192.168.27.1 > 192.168.31.155: ICMP echo request, id 1295, seq 2, length 64 20:04:52.688367 IP 192.168.27.1 > 192.168.31.155: ICMP echo request, id 1295, seq 3, length 64 Apparently, a client end sees ping packets, but doesn't respond, right?
A firewall can certainly control the direction TCP connections can be established in, by passing TCP packets with the SYN flag set but the ACK flag unset in one way only. The fact that you can SSH normally only indicates that packets either with no SYN flag at all or with both SYN and ACK flags set are allowed in both directions. To establish a TCP connection, a system must send a packet with the TCP SYN flag set and ACK flag unset, and a firewall can easily tell these apart from other packets. Pings are ICMP packets, not TCP packets, so a firewall can easily have a different rule for them. Also, a firewall could easily have one rule for "ping requests" and a different rule for "ping responses".
What subsystem is responsible if I can connect via s2s VPN connection only in one direction?
1,440,610,426,000
Yesterday I had issues with my database server dropping packets with: [Tue Feb 28 21:01:00 2023] nf_conntrack: nf_conntrack: table full, dropping packet I know there a plenty of solutions easy to find in google to increase the table size. So I did sysctl -w net.netfilter.nf_conntrack_max=4194304 But they also say to increase the hash table, and they are all for different linux distributions or very old kernels. echo "options nf_conntrack expect_hashsize=1048576 hashsize=1048576" >/etc/modprobe.conf Is this the right way to do in Ubuntu 18.04 with kernel 4.15 (default) or newer I use 5.11 And how can I verify if the new hashsize is being applied? and how to apply it without a reboot?
I finally found the answer... it can be done with sysctl.conf. The parameter is net.netfilter.nf_conntrack_buckets
What is the correct way to increase nf_conntrack in ubuntu 18.04?
1,440,610,426,000
The Qemu VM can be connected to LAN mainly in two ways: type=user or type=tap. The user mode completely isolate the VM in private network, which is sNATed to host main network stack. The use of tap is more complicated, it needs a virtual bridge to become a master of a physical interface (eth0) and virtual interface (tap0). The tap0 is like a pipe for data flowing from outside the world and host to the VM. I spent lot of hours while trying to regulate the network traffic on the tap0 interface with host side iptables/nftables to redirect for example all http requests to some internal ip address, but no success. All advice, forums, and wiki recommends plenty of solutions, which cannot work, because of the main reason: The packets from the VM guest never come to host kernel network stack. They choose their way on the bridge level and do not meet any firewall rule tuned up by any chains of packet filter, if the IP host address is not their target. You can try it simply by setting the host global policy to DROP (with host XYtables), and you can see: the host networking is completely dead, but the guest can continue to send and receive packets over the net. Well, the question: Is there some other way, how to virtually connect the VM guest to a host virtual network interface? For better understanding the graphs follow: General virtual connections for host/VM guest +---------------------------------------------+ | +-----------------------------+ | | | iptables host kernel | | | | nftables network stack | | | +-------+---------------------+ | | | | | +-------+---------+ +-----------+ | ---eth0--+ virtual | | VM | | | | bridge +-tap-eth0 guest | | ---eth1--+ br0 | | | | | +-----------------+ +-----------+ | +---------------------------------------------+ Host became a router for VM guest +-------------------------------------+ | +----------------+ +---------+ | ---eth0--> host kernel | | VM | | | | <-vppp guest | | ---eth1--> network stack | | | | | +----------------+ +---------+ | +-------------------------------------+ To solve my problem there must be find either a way how to control (with nftables e.g.) the traffic of the virtual bridge itself, either how to connect the VM guest network interface though a virtual wire to a virtual network interface of the host. Something like a PPPoE networking. But the ultimate and the most clear way is to add some more parameters to the Qemu user mode networking to be able to force redirect some port(services) to chosen target address, the host loop-back included. Yes I sent such wishes to the Qemu team, and got an answer: it is not the top most necessary feature.
There are two possible solutions: Use nftables bridge family and do filtering below layer 3. Use the host as a router. The first solution is the more efficient option, but limits you to filtering on properties of the Ethernet frames. You can’t filter on IP addresses or ports, or anything else at layer 3 or higher, because the bridge does not process any of that data. The second solution is more likely to allow you to do what you want here. This is actually very simple for two specific reasons: You can assign an IP address on a bridge interface directly, just like with any other network device type. You don’t need to have any physical network devices connected to a bridge interface. Give this, the ‘normal’ setup for what you want to do is: Set up a bridge interface on the host system. Assign a static IP to it, but do not connect it to any physical interfaces. Configure nftables so that the system handles routing between the bridge interface from step 1 and any external interfaces. When starting a VM, attach it to the bridge interface from step 1. Then, you just filter things in nftables no differently from if the system were acting as a perimeter firewall. You can make this even easier by setting up a DHCP server and caching DNS resolver on the host system so that you don’t need to give the VM static networking configuration.
How to secure the tap interface with nftables
1,440,610,426,000
I have to setup an stateful firewall on centos8 using firewalld. I'm new to firewalld but have experience with old style iptables for this purpose. since it is recommended by Redhat here, I prefer to not combine two methods like firewalld and iptables. I want to know is there a way to use firewalld in stateful mode? if it is how? thank you
Firewalld configures iptables or nftables, and the resulting configuration is stateful (based on connstate status: established, related, untrack, invalid, new). You can check the actual configuration with iptables -L -n -v and nft list ruleset. You can choose which backend you want to use in /etc/firewalld/firewalld.conf with the option FirewallBackend. If you want Firewalld to use iptables, you have to set: FirewallBackend=iptables If you want to disable Firewalld to use you standard iptables configurations, you can use: systemctl disable firewalld --now systemctl mask firewalld
how to use firewalld in stateful mode
1,440,610,426,000
On my host Ubuntu 18.04 I am running two lxc containers using default setups. Containers use Ubuntu 18.04 as well. I have an app running on container1 that offers an https based service on https://localhost:3000/. Container2 is not able to even establish a connection with container1. Container2 can ping container1 and read the html of the default Apache2 server running on localhost (for container1). Testing with netcat, I can establish connection with a few main ports, however I get connection refused for port 3000. root@c2:~# nc -zv c1 22 Connection to c1 22 port [tcp/ssh] succeeded! root@c2:~# nc -zv c1 80 Connection to c1 80 port [tcp/http] succeeded! root@c2:~# nc -zv c1 443 nc: connect to c1 port 443 (tcp) failed: Connection refused nc: connect to c1 port 443 (tcp) failed: Connection refused root@c2:~# nc -zv c1 3000 nc: connect to c1 port 3000 (tcp) failed: Connection refused nc: connect to c1 port 3000 (tcp) failed: Connection refused The same situation applies between my host and any of my containers. Only ports 22 and 80 seem to be reachable by default. I tried enabling ufw on all containers, but it still doesnt work out: root@c1:~# ufw status Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere 22/tcp ALLOW Anywhere 22 ALLOW Anywhere 443 ALLOW Anywhere 873 ALLOW Anywhere 3000 ALLOW Anywhere Anywhere on eth0@if16 ALLOW Anywhere Apache ALLOW Anywhere 80 ALLOW Anywhere 20 ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) 22/tcp (v6) ALLOW Anywhere (v6) 22 (v6) ALLOW Anywhere (v6) 443 (v6) ALLOW Anywhere (v6) 873 (v6) ALLOW Anywhere (v6) 3000 (v6) ALLOW Anywhere (v6) Anywhere (v6) on eth0@if16 ALLOW Anywhere (v6) Apache (v6) ALLOW Anywhere (v6) 80 (v6) ALLOW Anywhere (v6) 20 (v6) ALLOW Anywhere (v6) Anywhere ALLOW OUT Anywhere on eth0@if16 Anywhere (v6) ALLOW OUT Anywhere (v6) on eth0@if16 Even testing via curl clearly shows me that port connection is closed and thats the issue: root@c2:~# curl https://10.155.120.175:3000/ curl: (7) Failed to connect to 10.155.120.175 port 3000: Connection refused I have been stuck in this issue for a week, can anyone help me troubleshoot this? Edit (additional data): results for netstat on container1: root@c1:~# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 289/systemd-resolve tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1385/sshd tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN 293/MyApp tcp6 0 0 :::80 :::* LISTEN 310/apache2 tcp6 0 0 :::22 :::* LISTEN 1385/sshd
Port 3000 is only listening for localhost. You need to configure your application correctly so that the port is open to 0.0.0.0 (as you can see in other ports).
Connection refused between 2 linux containers
1,440,610,426,000
I connected to my remote Linux server to adjust my network settings, but I accidentally changed some rules using iptables instead of my preferred method, ufw. I added the rules in ufw and then ran iptables -F to flush the rules from iptables. However, I forgot that this would block my SSH connections. I would like to connect to my server again via SSH, but even though the port I am using for SSH is allowed on ufw, my flush of iptables is blocking me from connecting. If I ask the server maintainer to manually reboot the server (i.e., disconnect and reconnect the power cord), will ufw reconfigure iptables to allow SSH connections (as configured in the ufw rules), or do I need to log into the server via a local TTY and reenter the rules into ufw to solve the problem?
ufw doesn't need to flush iptables rules on reboot. That happens automatically...or, more precisely, there are no iptables rules on a freshly booted Linux system until something sets them. ufw does exactly that. It will set the iptables rules to exactly what its configuration files tell it to set them as. That's why programs like ufw exist - iptables rules are not persistent across reboots, so programs like ufw exist to provide persistence for firewall rules.
Does UFW reset iptables on reboot?
1,440,610,426,000
Could anyone help me with a review of my iptables rules (running a new Tor relay server), please? I'm running a Debian GNU/Linux 11 (bullseye), fully updated. I drop everything in INPUT chain by default, SSH port is censored, so if you see XXYYZ... I changed it to a custom port so that the bots have a little bit more work than just hit the 22. I will copy-paste the rules.v4 file now: # Latest revision on 2021-Jul-25 *filter :INPUT DROP [0:0] :FORWARD DROP [0:0] :OUTPUT ACCEPT [0:0] --append INPUT --match conntrack --ctstate NEW --protocol tcp ! --syn --match comment --comment "protection: non-syn packets" --jump DROP --append INPUT --match conntrack --ctstate INVALID --match comment --comment "protection: malformed packets" --jump DROP --append INPUT --in-interface lo --match comment --comment "loopback: compulsory" --jump ACCEPT --append INPUT --protocol icmp --icmp-type echo-request --match limit --limit 2/second --limit-burst 5 --match comment --comment "ICMP: ping only" --jump ACCEPT --append INPUT --match conntrack --ctstate RELATED,ESTABLISHED --match comment --comment "Tor: traffic" --jump ACCEPT --append INPUT --match conntrack --ctstate NEW,ESTABLISHED --protocol tcp --match tcp --destination-port XXYYZ --match comment --comment "SSH: global obfuscated" --jump ACCEPT --append INPUT --protocol tcp --match tcp --destination-port 9001 --match comment --comment "Tor: OR" --jump ACCEPT --append INPUT --protocol tcp --match tcp --destination-port 9030 --match comment --comment "Tor: Dir" --jump ACCEPT COMMIT The current output of about one day's uptime is: # iptables -L INPUT -v --line-numbers Chain INPUT (policy DROP 29718 packets, 3008K bytes) num pkts bytes target prot opt in out source destination 1 234 131K DROP tcp -- any any anywhere anywhere ctstate NEW tcp flags:!FIN,SYN,RST,ACK/SYN /* protection: non-syn packets */ 2 374 45284 DROP all -- any any anywhere anywhere ctstate INVALID /* protection: malformed packets */ 3 96 4800 ACCEPT all -- lo any anywhere anywhere /* loopback: compulsory */ 4 24 902 ACCEPT icmp -- any any anywhere anywhere icmp echo-request limit: avg 2/sec burst 5 /* ICMP: ping only */ 5 3736K 2726M ACCEPT all -- any any anywhere anywhere ctstate RELATED,ESTABLISHED /* Tor: traffic */ 6 30 1800 ACCEPT tcp -- any any anywhere anywhere ctstate NEW,ESTABLISHED tcp dpt:XXYYZ /* SSH: global obfuscated */ 7 12493 743K ACCEPT tcp -- any any anywhere anywhere tcp dpt:9001 /* Tor: OR */ 8 7948 423K ACCEPT tcp -- any any anywhere anywhere tcp dpt:9030 /* Tor: Dir */ The server seems to work like a charm, but I may be simply over-confident, for the lack of a better word.
For your reference: *filter -N RNNS -A RNNS -p tcp ! --syn -j REJECT --reject-with tcp-reset # accept (new) syn -A RNNS -j ACCEPT -N ALLOW # tcp (r)eset (n)ew but (n)ot (s)yn # -j RNNS is fine too since the chain has a "fallback" verdict at the end -A ALLOW -p tcp --dport 9001 -g RNNS -A ALLOW -p tcp --dport 9030 -g RNNS -A ALLOW -p tcp --dport 12345 -g RNNS # for (new) udp, just accept -A ALLOW -p udp --dport 54321 -j ACCEPT # others' fate will be determined by the chain policy of INPUT # because we came to this chain by -g # but well, -g ALLOW was the last rule anyway, so -j would have worked too # and you can -j DROP here anyway -P INPUT DROP -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A INPUT -m conntrack --ctstate INVALID -j DROP # -A INPUT -m conntrack --ctstate INVALID ! -p tcp -j DROP # could only be of conntrack state NEW; oh well, also see UNTRACKED -A INPUT -i lo -j ACCEPT # -A INPUT -i lo -g RNNS -A INPUT -p icmp --icmp-type echo-request -m limit --limit 2/second --limit-burst 5 -j ACCEPT # chain policy; optimization / optional -A INPUT -p icmp -j RETURN # won't be ICMP -A INPUT -g ALLOW -P FORWARD DROP -P OUTPUT ACCEPT COMMIT Note that the order of the rules in the same chain could matter a lot, but certainly the order among rules that have no logical relation does not (see the chain ALLOW), although as an "optimization", we prioritize matching that are more "important" / likely to be true (see the first two --ctstate rules in the INPUT chain) when we can.
Review iptables on a VPS (running Tor non-exit relay)
1,440,610,426,000
I just freshly install a new machine running on linuxmint-19.2-xfce-64bit. I set the Gufw to block all incoming and outgoing traffic but my system still receive an IP address! The software manager fetch result on query (unless this is local ??) but Firefox is at least blocked. So how I can simply block everything? Also when a process try to make a connection, I want that I'm warned on screen, by a window, pop-up or similar notification?
On Linux, the standard network stack forbids to send an IP packet with source IP 0.0.0.0 (probably since kernel 2.2). As this is required by the DHCP protocol, DHCP tools must bypass this limitation. Thus DHCP clients rely on RAW sockets to craft this forbidden packet with source IP 0.0.0.0 and actually use them for the initial DHCP exchanges. Those packets are bypassing the network stack, including iptables. Here are some related links quickly found: A Guide to Using Raw Sockets Red Hat Bugzilla – Bug 1269914 - can't firewall packets coming through raw sockets ISC - How DHCP uses raw sockets Anyway it's possible to firewall this by using an Ethernet bridge, even if it's not needed for anything else. So you could choose to create a bridge interface and enslave your unique Ethernet interface in it (beware, Wireless Wifi interfaces usually don't work on a bridge without complex settings), and set the DHCP client to use the bridge's self interface rather than the original ethernet interface. The packets emitted by the DHCP client will then be switched, so subject to bridge firewalling using ebtables (nftables could also be used instead): ebtables -A OUTPUT -j DROP same for received packets: ebtables -A INPUT -j DROP Or if you don't want to do this, you must go even lower, at the interface level, which is possible when using tc. Let's suppose your interface is called eth0 (your picture is hard to read): Add a classful simple qdisc to be able to attach filters: tc qdisc add dev eth0 root handle 1: prio Add a match all/drop all filter and action: tc filter add dev eth0 parent 1: matchall action drop Now nothing will be able to go out of the interface, but incoming packets can still be seen if needed. (You can revert everything with tc qdisc del dev eth0 root) Similarly you can block all incoming data: tc qdisc add dev eth0 ingress tc filter add dev eth0 ingress matchall action drop (cancel with tc qdisc del dev eth0 ingress) I can't tell it's simple, but the tc method achieves complete lockdown in 4 commands, and it won't need reconfiguring other network tools like NetworkManager, like would probably be needed with the use of a bridge (and it will also work on Wifi).
Looking for a simple but effective firewall
1,440,610,426,000
I installed firewalld on my Debian 10 laptop. Now Transmission cannot upload properly. If I go in to Edit->Preferences->Network and click [Test Port], it says the port is closed. If I systemctl stop firewalld and restart Transmission, then it says the port is open. How can I use Transmission with a firewall?
Firstly, in the same Network tab of the Preferences window, make sure that "Pick a random port every time Transmission is started" is unchecked. Also check what the Listening Port is set to. The default port number is 51413. In your firewall, allow the TCP port number set above. Since you are using firewalld, you can allow port 51413 by allowing the named service "transmission-client". If your router supports NAT-PMP, or if you configured your router with a manual port forward, this is all you need! Transmission will now work with your firewall. NAT-PMP is available on Apple routers. It is also available on any sensibly written router with a recent version of the open source MiniUPnPd. This works great on OpenWRT routers :-). Or if you need support for IPv6 (the current version of IP :-), just pretend I said NAT-PCP instead of NAT-PMP. Otherwise, you probably relied on uPnP port forwarding. This is a problem, sorry. If you do not wish to configure a manual port forward on your router, there are some possible techniques on this page: Fedora firewall with UPnP? Terrible ways to allow uPnP, that you should not use 1. firewalld service "upnp-client" firewalld has a named service "upnp-client". Allowing this service might let Transmission work. But allowing this service means an attacker can bypass the firewall for any UDP port, if they transmit from UDP port 1900. The firewalld service for "upnp-client" is defined using <source-port ... />. This is different from <port ... />, which is used in most firewalld service definitions. There is a parenthetical disclaimer about this, but the firewalld interface fails to show it. $ cat /usr/lib/firewalld/services/upnp-client.xml <?xml version="1.0" encoding="utf-8"?> <service> <short>UPnP Client</short> <description>Universal Plug and Play client for auto-configuration of network routers (use only in trusted zones).</description> <source-port port="1900" protocol="udp"/> </service> 2. minissdpd In the previous version of Debian, installing Transmission would automatically install minissdpd. Transmission can use minissdpd to receive uPnP responses, and this appears to work better with a firewall. If you allow UDP port 1900 in the firewall, then Transmission will be able to set up uPnP port forwards. The problem is that minissdpd is a big security risk. minissdpd needs to be configured with a list of network interface names that it should run on. Debian will suggest a default list. Make sure to check this carefully if you have multiple possible network interfaces, e.g. both Wi-Fi and wired Ethernet. Once minissdpd is running, remember to allow UDP port 1900 in your firewall, and then restart Transmission. I note this approach does not work on Fedora Linux. minissdpd is not available in Fedora, and Fedora does not build Transmission with support for libminiupnp.
Transmission (Gnome BitTorrent client) v.s. firewall on Debian 10
1,440,610,426,000
My iptables output looks like this: Chain INPUT (policy ACCEPT) num target prot opt source destination 1 DROP all -- 0.0.0.0/0 0.0.0.0/0 match-set sshd src Chain FORWARD (policy ACCEPT) num target prot opt source destination Chain OUTPUT (policy ACCEPT) num target prot opt source destination How can i check to see if this "sshd" set was already hooked up to iptables? Thanks
You can use -C flag in iptables to check if a set exists: sudo iptables -C INPUT -m set --match-set sshd src -j DROP Return code is > 0 if the set does not exist.
how to check whether an ipset was hooked up to iptables
1,440,610,426,000
I have VMs in virt-manager. Normally, they can connect to the internet. These VMs are connected to my default virtual network, device virbr0. To reach the internet, the virtual network is configured as "NAT forwarding". But the VMs can no longer connect to the internet. They can ping the host, on the IP address 192.168.122.1, which the VMs see as their default router. However, ping google.com hangs for 5 seconds and then returns No address associated with hostname. I thought this might be a problem with the host firewall. I tried systemctl stop firewalld, and now sudo iptables-save shows as empty, but the VMs still cannot connect to the internet. Strangely, ping google.com now is able to resolve an IP address, but does not show any ping replies, nor any ICMP errors. I.e.: PING google.com (216.58.198.174) 56(84) bytes of data. ^C --- google.com ping statistics --- 44 packets transmitted, 0 received, 100% packet loss, time 44018ms What could have gone wrong? How can I find out?
now sudo iptables-save shows as empty, but the VMs still cannot connect to the internet. The NAT forwarding on the virtual network uses iptables rules. Therefore if the iptables rules are empty, it cannot work :-). The problem happened because I had already stopped and started firewalld, to diagnose a different issue. This wiped out the necessary iptables rules. To reset the virtual network, re-creating the necessary iptables rules, run systemctl restart libvirtd.
Virtual network virbr0 cannot connect to internet anymore
1,440,610,426,000
I'm quite stumped/frusterated as I can't get postfix to work on one of my VM's. It is a "template" VM and I have setup other VM's with this template fine. The only difference I can really think of is this VM's purpose which is ZoneMinder security software. I tried using telnet mail.domain.com 25 & ssh [email protected] and I get No Route To Host for both. Both of these work from other VM's inside the LAN and the mail.domain.com is also inside the LAN. Here is the network config from the VM in question (which is Ubuntu 18 BTW): root@sub:~# cat /etc/network/interfaces # ifupdown has been replaced by netplan(5) on this system. See # /etc/netplan for current configuration. # To re-enable ifupdown on this system, you can run: # sudo apt install ifupdown # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto ens3 #iface ens3 inet dhcp iface ens3 inet static address 192.168.1.255 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 192.168.1.1 dns-search domain.com Here is the Hosts file: root@sub:~# cat /etc/hosts 127.0.0.1 localhost sub.domain.com sub ::1 localhost6 sub6.domain6.com sub6 # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts And finally, I was able to SSH to other VM's in the LAN so I'm quite stumped. Any pointers or more information needed let me know. Thank You Update: I am able to ping mail.domain.com from other VMs but not the one in question, I have never had this issue before. Eg: root@sub:~# ping mail.domain.com PING mail.domain.com (192.168.1.237) 56(84) bytes of data. From 192.168.1.255 (192.168.1.255) icmp_seq=1 Destination Host Unreachable From 192.168.1.255 (192.168.1.255) icmp_seq=2 Destination Host Unreachable From 192.168.1.255 (192.168.1.255) icmp_seq=3 Destination Host Unreachable Update2: I have now removed the NIC from the VM and added a new one in case there was duplicate MAC issue. I changed the IP address and the DNS entry in the gateway. I rebooted the gateway after the above two steps still didn't work and I have been flushing the arp cache via ip -s -s neigh flush all periodically along w/ reboots just to make sure that isn't the issue.
I'm not 100% the issue (but it's fixed now!), but I found these two threads helpful. From 192.168.0.146 icmp_seq=1 Destination Host Unreachable Host unreachable and I do not get why Basically it was one of two things: A duplicate IP address conflict A duplicate MAC address conflict But, the trick was also to make sure to clear the arp cache via ip -s -s neigh flush all and/or reboot the VM/Target VM/Gateway Router. I'm fairly certain my issue was a duplicate MAC address. I generally use disks as a template and create a new VM via the GUI and just point it to the copy of the disk template. But, I think this time I used a domain.xml and modified the disk parameter to point to the new disk. The issue was that domain.xml was still in use by the previous template VM w/ the same MAC.
No Route To Host from one VM on LAN
1,440,610,426,000
I've recently learned about the route-to functionality in the pf firewall, and I wonder how it works. Is it similar to the "policy-based routing" system in linux? How does route-to allow the overriding of the system routing table?
Pf's route-to allows to define policy-based routing (PBR) using the same firewall's ruleset. The PBR itself is then being done at kernel-level during traffic processing according to firewall ruleset shipped onto kernel level by pf's user-space utility pfctl. In Linux, Netfilter (which many people erroneously call iptables by its main control utility's name) stays away from PBR functionality except that it still can be used to change/assign "marks"1 that PBR's rules2 might make use of in addition to other "selectors". __ man iptables-extensions's excerpt: MARK — This target is used to set the Netfilter mark value associated with the packet. It can, for example, be used in conjunction with routing based on fwmark (needs iproute2). If you plan on doing so, note that the mark needs to be set in the PREROUTING chain of the mangle table to affect routing. The mark field is 32 bits wide. user space utility ip (of that "iproute2") is typically used for that: ip rule …
How does route-to work in the BSD pf firewall?
1,440,610,426,000
I deploy an Ansible playbook to some debian:stable machines aiming to update package index cache, install ufw and setup it in the Ansible architecture-agnostic and version-agnostic way. - name: Update all apt package index cache (apt update) apt: update_cache=yes - name: Install a latest ufw apt: name: ufw state: latest - name: Setup firewall with ufw ufw: rule: allow port: 22,25,80,443 My difficulty here In Bash I also regularly use ufw --force enable but I didn't find how to add it to the playbook in Ansible-YAML syntax in Ansible ufw documentation. My question How should I add ufw --force enable correctly, if at all?
If you just want to run shell commands, you use the Ansible shell or command modules. As far as ufw goes, I think it directly edits the rules files. Looking at the source code, it's running this, before and after the actions to check if these files have changed contents. grep '^### tuple' /lib/ufw/user.rules /lib/ufw/user6.rules /etc/ufw/user.rules /etc/ufw/user6.rules As far as enabling, or disabling, that is what the state action is for If you say state: enabled, it'll do ufw -f enable if command == 'state': states = {'enabled': 'enable', 'disabled': 'disable', 'reloaded': 'reload', 'reset': 'reset'} execute(cmd + [['-f'], [states[value]]])
Ansible orchestration for ufw with ufw --force enable
1,440,610,426,000
Simple question: What is the priority if we have both firewalld and iptables in use? Which takes the priority in the rules. For example, if I block ICMP with firewalld and with iptables I accept it, what happens?
Firewalld uses iptables to implement its rules. If require some iptables features not implemented in firewalld, you can configure iptables rules directly in firewalld . Using more than one tool to manage iptables rules might otherwise cause problems. Iptables rules are evaluated in order, processing for a packet stops on first matching rule. Using your example: if you accept the icmp as the first rule in INPUT chain, the packet will be accepted even if there is a later drop rule, since it will not get evaluated. Similarly if you add accept at the end of the chain and there is an earlier (firewalld generated) rule to drop it, the packet will be dropped.
Firewalld and iptables priority
1,440,610,426,000
I have a server with a proxmox installation and only 1 outbound connection (eth0). To make the machines network between each other I created a network bridge (vmbr0) in the interfaces configuration and configured it accordingly to the Proxmox Network Model (Subpoint NAT). The bridge has the IP 10.1.1.1 and acts in my understanding as a getway between the local network and the wide world. To achieve this, following iptable policies are implemented on the server: Chain FORWARD (policy DROP) target prot opt source destination ACCEPT all -- 10.1.1.0/24 anywhere ACCEPT all -- anywhere 10.1.1.0/24 Chain POSTROUTING (policy ACCEPT) target prot opt source destination SNAT all -- 10.1.1.0/24 anywhere to:x.x.x.x When I ping the Google DNS server from one of the vms installed on the server and connected via the bridge using: ping 8.8.8.8, the vm is able to get a ping result from the Google DNS server so the NAT seems to be working. (The nat is again for the whole Subnet (10.1.1.0/24) ) If I do: ping -I vmbr0 8.8.8.8 on the host machine however, the ping command fails. This ping commands uses the bridge interface to ping the Google DNS server and my expectation was, that the POSTROUTING policies would make it able to communicate with the Google DNS server too. So in short, when other clients using the bridge as gateway they can connect to the internet, but if the interface itself is selected as outgoing interface it can't find a route. So this leads me to my question, is explicitly using an interface somehow skipping postrouting rules and is really taken as the absolute endpoint for routing on the concerning machine? - in a sense: vmbr0 stays vmbr0 and never will be masqueraded to eth0 if you choose to ping over it -
man ping, bolds mine: -I interface interface is either an address, or an interface name. If interface is an address, it sets source address to specified interface address. If interface in an interface name, it sets source interface to specified interface. The issue is with forcing the interface with ping -I vmbr0 instead of letting the system choose in the end the right interface with ping -I 10.1.1.1. Also, even if this doesn't make a difference with nat/POSTROUTING (see later), you should understand that you're not routing when running a command on the host, so some chains (eg: filter/FORWARD) might not apply (but nat/POSTROUTING still does, see later). Keep in mind that this might give different results when running commands on the host instead of a routed VM depending on your rules, even if that's not the case here with the right ping command. this Packet Flow in Netfilter and General Networking schematic shows that after the different OUTPUT chains are traversed for a packet coming from a local process, nat/POSTROUTING still gets traversed after, so yes had your packet be going outside through eth0 it would still have been SNATed: that's by using ping -I 10.1.1.1 8.8.8.8 Instead when forcing the interface with ping -I vmbr0 8.8.8.8, if you run tcpdump on vmbr0 you'll likely see ARP requests from 10.1.1.1 to 8.8.8.8 which won't get answers. And for the final question: yes forcing the route can't let the packet go to the right destination. You can't ever have vmbr0 be masqueraded, because SNAT/MASQUERADE is done on packets' IP, not on an interface, and its application depends on their route to the destination.
Does ping omit iptables / postrouting rules
1,515,464,161,000
Do I need port 993 unfiltered to get emails from a WordPress site? For example, in WordPress I've installed a plugin called "Contact form 7" (CF7) that gives you a basic contact form. In the plugin settings you can insert your email (say, [email protected]) and messages left in your WordPress CF7 contact form will be forwarded to your private email by this plugin. I've filtered all port besides 22, 80, 443, 993, and 9000. Do I really need port 993 unfiltered for the trivial contact form behavior I just described?
You most likely won't need it. Port 993 is related to IMAP, which implies email clients (mutt, thunderbird, ...) connecting to their mailboxes on your server. Assuming from your question, you're looking to setup a smtp relay, hence do not need to allow in traffic for potential clients - and probably won't have a service listening on these anyway.
Do I need port 993 to get email in a WordPress site?
1,515,464,161,000
I've got many rules like: -A POSTROUTING -s IP_LOCAL1 -j SNAT --to-source IP_PUBLIC1 -A POSTROUTING -s IP_LOCAL2 -j SNAT --to-source IP_PUBLIC2 ... ... -A POSTROUTING -s IP_LOCAL100 -j SNAT --to-source IP_PUBLIC100 Is there any possibility to make an ipset with declaration IP_LOCAL1:IP_PUBLIC1 and then make only one rule using ipset?
No. Currently it is not possible to use ipset as SNAT directives.
IPset and making firewall simple
1,515,464,161,000
I am building a secure server (Debian with GUI) for offline signing transactions. I don't need internet access. However I would like to have my system automatically update. How can I achieve this?
A local repo or repo-cache is needed. For a local deb mirror: setup a web server get apt-mirror configure apt-mirror: there are three items that should be modified within the apt-mirror config file. /etc/apt/mirror.lst point within your web hosted pages. set base_path <somewhere_in_your_web_hosted_page> in my specific instance, amd64 was all that was needed, so to save space I specified. set defaultarch amd64 and limit your download rate… It may be important to limit the download rate in a corporate environment, unless want to negatively impact production applications or sites, trigger the burst rate on your corporate pipe and have a potentially uncomfortable meeting with management about burst rate overage costs. set limit_rate 1m In a security and patch centric environment use at least a two-stage local mirror. First, move the prior day’s external pull up the chain to the “production” mirror with rsync. By using rsync, the testing mirror isn’t erased, so apt-miror is only pulling those items that are newly updated, not everything. After that synchronization, trigger the apt-mirror, against the “testing” mirror. Less critical servers, update from the testing mirror, to make sure that nothing terrible happened, then the production servers update from the production mirror. This can all be automated with cron or another type of job manager.
How to allow only apt internet access any deny / block everything else
1,515,464,161,000
I have a router, which I want to configure to block all outgoing traffic to the Internet. As far as I understand, I need to drop forwarded packets. In addition I want to allow traffic between one machine and several other machines in the internal LAN. To do tried the following: IPT="/sbin/iptables" LOCAL_CONTROLLER="192.168.1.2" SUBNET="192.168.1." MACHINE_IPS="100 101 102 103 104" for MACHINE in ${MACHINE_IPS}; do $IPT -A FORWARD -s $LOCAL_CONTROLLER -j ACCEPT $IPT -A FORWARD -s $SUBNET$MACHINE -m state --state ESTABLISHED,RELATED -j ACCEPT $IPT -A FORWARD -s $SUBNET$MACHINE -d $LOCAL_CONTROLLER -j ACCEPT $IPT -A FORWARD -s $SUBNET$MACHINE -j DROP done Unfortunately, this does not work as I expected, and traffic from 192.168.1.2 to 192.168.1.103 and back is blocked. Can you point out where my script is wrong?
The FORWARD queue is only used when the server is question is the router, for dealing with incoming/outgoing packets outside of your network; it is used for blocking/accepting the routing of packets outside your network (at router level). For controlling connections at host level, you normally use INPUTor OUTPUT queues, no matter where the connections are coming from, as they do not do routing (e.g. do not do IP Forwarding). If you really want a group of machines in a local network to talk among themselves, and not talk with the Internet, the simplest approach of all is not defining a gateway on that machines. If you still with to do with iptables you have to use the INPUT queue in your script in lieu of FORWARD. If your main worry is traffic going to the Internet, whilst I do prefer not giving them a gateway to go out, you have to use the OUTPUT queue in the local machines. As in: iptables -A OUTPUT -d 192.168.1.0/24 -j ACCEPT iptables -A OUTPUT -j DROP (192.168.1.0/24 -> all the machines in the 192.168.1 network) Be aware that if you coming via ssh from another network, you will effectively lock yourself out with these rules. However, if your router is a linux box, it maybe enough to write as a FORWARD rule to lock a couple of machines from the Internet: iptables -A FORWARD -s 192.168.1.10 -j DROP iptables -A FORWARD -s 192.168.1.11 -J DROP From man iptables: INPUT (for packets destined to local sockets) FORWARD (for packets being routed through the box) OUTPUT (for locally-generated packets).
IPTables - allow communication between two hosts , drop everything else
1,515,464,161,000
I'm a little lost and hope someone can point me into the right direction to solve my problem. I have a server running with a Debian distribution and I'm using UFW as firewall. The configuration and setup was pretty easy and I started the firewall as documented with: manly@server:~$ sudo ufw enable Command may disrupt existing ssh connections. Proceed with operation (y|n)? y Firewall is active and enabled on system startup If I check, if ufw is running I receive (correctly): manly@server:~$ sudo ufw status Status: active To Action From -- ------ ---- 22 ALLOW Anywhere 80/tcp ALLOW Anywhere 22 ALLOW Anywhere (v6) 80/tcp ALLOW Anywhere (v6) After some time (I check daily), the firewall turns inactive - even without any restart in between -, i.e., status returns inactive: manly@server:~$ sudo ufw status Status: inactive I have no idea why. What can I check to figure out the reasons behind that weird behavior. I'm thankful for any advice! Update: I noticed something, which may help to find a solution. So I start the ufw with the sudo ufw enable in an ssh session. It seems like, that if I keep the ssh session open, the firewall is enabled. If I close the ssh session (exit), the ufw status will be set to inactive after some time. Do I have to start the ufw in any special manner?
So after some digging and talking to the support, we finally figured out, what stops UFW. The system also had APF (Advanced Policy Firewall - R-fx Networks) configured, which adds a cron-job to the system. The job removes all rules on midnight and resets the rules defined for APF.
UFW (Uncomplicated Firewall) turns off (inactive) after a while
1,515,464,161,000
Following IPTables rules exist on my system as some preventive measures against DDoS attacks -A INPUT -s 255.0.0.0/8 -j LOG --log-prefix "Spoofed source IP" -A INPUT -s 255.0.0.0/8 -j DROP -A INPUT -s 0.0.0.0/8 -j LOG --log-prefix "Spoofed source IP" -A INPUT -s 0.0.0.0/8 -j DROP Is it restricting private IP Address Group with the assumption that packets originating from private IP Address range from Internet are actually spoofed IP Address. Also, How to calculate the corresponding IP Address range from the above subnets ?
The -A INPUT -s adds a rule for any packets with the source subnets specified on the line. Therefore, in your example, you are logging and dropping all packets that have a source IP address that starts with 255 and all that start with 0, such as 255.1.2.3.4 or 0.56.78.90 The idea here is that there should will never be packets that start with those addresses and therefore if they do appear, they must be spoofed. There are actually many more invalid or reserved IP addresses that the ones you've listed which could be added to that list. There are plenty of resources on subnets and plenty of online subnet calculators to help you out. In your case, the /8 states that the first 8 bits of the IP address specify the network and all the others (the remaining 24) specify a host within that subnet. In both examples, the first octet (8 bits) is the network and the other three octets can be any value. Your 255.0.0.0/8 therefore can be from 255.0.0.0 to 255.255.255.255 and your 0.0.0.0/8 can be from 0.0.0.0 to 0.255.255.255.
Understanding Iptables rules to prevent DDoS
1,515,464,161,000
Will VyOS still work right if I install Shorewall-lite on it? Shorewall seems like an easier way to setup a network, but VyOS seems pretty great for day-to-day management of a router / firewall. So I was wondering if they are compatible. From what I understand about Shorewall, it just generates a bunch of iptables rules, and VyOS is a Linux dirstro with iptables, so it seems to me that it should work, but I thought I would just check if there were any other caveats about why they are not compatible that I should know about before putting the research into setting something like this up.
Shorewall-lite is a very light weight tool to manage a firewall configuration generated on another server. It is not suitable for setting up the configuration, but does manage the generated configuration. It runs quite well on OpenWRT, which is a distribution intended for routers. The current version of Shorewall is Perl based. This can make the installation much larger than you would want for a router. Of the tools I have used, I find Shorewall the easiest to use. There are example configuration which generally require little modification. I have done fairly complex configuration for a smaller network quite easily.
Can Shorewall be used on VyOS?
1,515,464,161,000
I have iptables firewalls and its logging for all DROP packets or Deny. I want to tell it to no LOG any packet for ICMP protocol. How do i tell that *filter :INPUT DROP [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [24:5541] :DROPLOG - [0:0] -A INPUT -s 108.34.21.45 -j ACCEPT -A INPUT -s 210.23.72.22 -j ACCEPT -A INPUT -s 108.35.98.7 -j ACCEPT -A INPUT -s 167.98.200.1 -p icmp -m icmp --icmp-type any -j ACCEPT -A INPUT -s 172.56.21.10 -p icmp -m icmp --icmp-type any -j ACCEPT -A INPUT -s 185.201.88.91 -p icmp -m icmp --icmp-type any -j ACCEPT -A INPUT -j DROPLOG -A DROPLOG -j LOG --log-prefix "DENY: " --log-level 6 -A DROPLOG -j DROP COMMIT Here is the log sample: DENY: IN=eth0 OUT= MAC=00:36:55:7a:3b:6c:00:31:d7:ba:a4:00:08:00 SRC=84.137.71.48 DST=108.101.99.137 LEN=88 TOS=0x00 PREC=0x00 TTL=118 ID=21684 PROTO=ICMP TYPE=3 CODE=3 [SRC=108.101.99.137 DST=192.168.2.102 LEN=60 TOS=0x00 PREC=0x00 TTL=54 ID=0 DF PROTO=UDP SPT=21458 DPT=62936 LEN=40 ] following stupid logs filling my disk... I want to tell iptables ignore ICMP. I don't want to use limit because i don't care of ICMP messges.
I suggest that you insert a -A INPUT -p icmp -j DROP before -A INPUT -j DROPLOG Drop the ICMP packets, then send the others to DROPLOG to get logged (and dropped).
iptables logging for all except ICMP
1,515,464,161,000
I need to isolate Subnets on a linux machine CentOS that act as gateway. I have the following scenario. CentOS eth0 pub ip addres eth0.1 192.168.1.1 eth0.2 192.168.2.1 Now eth0.1 and eth0.2 can communicate but i need to disable this. I can't use VLANs so i need to disable this communication with IPtables. Any idea ?
It's a bit tricky. You can isolate only traffic that passes through your gateway. For instance you can use that rules: iptables -I FORWARD -s 192.168.1.0/24 -d 192.168.2.0/24 -j DROP iptables -I FORWARD -d 192.168.1.0/24 -s 192.168.2.0/24 -j DROP or: iptables -I FORWARD -i eth0.1 -o eth0.2 -j DROP iptables -I FORWARD -o eth0.1 -i eth0.2 -j DROP Both subnets are on the same phisical interface so it looks nice only as long as you have control over all hosts/devices. Otherwise someone can bypass the gateway. There are many ways to do so. For example: change IP to become member of another subnet change IP to any other than one listed above set static, direct route to another subnet use IPv6 run DHCP server ... Short answer is that it cannot be done that way.
Isolate subnets on the same interface
1,515,464,161,000
Looks like this rule works to blocking facebook domain, when not visiting the facebook domain (ex.: "like/share" etc. buttons on other pages then facebook): ! don't allow facebook outside facebook.. ||facebook.com$domain=~www.facebook.com ||facebook.net$domain=~www.facebook.com ||fbcdn.net$domain=~www.facebook.com facebook.com###appsNav facebook.com###pagesNav facebook.com###groupsNav facebook.com###pagelet_friends_online facebook.com###pagelet_bookmark_nav facebook.com###pagelet_rhc_footer But how can I block completely twitter / g+ / etc sites with adblock rules? (Is this really effective, or it only makes me not to see the fcb buttons/etc.)?
You should try Ghostery to see if it doesn't do what you want. It's not a set of adblock rules, but rather an entire plugin devoted to webbugs, profiling, etc.
Adblock rule to block g+ / twitter / etc. [closed]
1,515,464,161,000
I have set up Apache, MySQL, PHP, SSH (which I use to connect to the VPS), Node.js, MongoDB and ProFTPd. Now, I want to have a firewall on the system, so that no one hacks the system. For instance, MongoDB is open for all on the default port unless I set it to secure mode and provide a password and so on. But it is recommended to have security mode off, and use a firewall to block requests on that port instead. How would I set up the firewall? (I am not experienced with Linux, and I can only use SSH.)
Any iptables tutorial should do the trick. Positive security is best. Block everything and only allow the traffic you specify. Layers of security is rarely a bad thing. MongoDB is famous for its insecurities, so I suspect secure mode is a good start. What hosting provider are you using?
How to set up firewall on Debian Squeeze
1,515,464,161,000
Is it possible to match only the DSCP portion of the IPv4 ToS or IPv6 traffic class byte using ebtables? I see that ebtables has the --ip-tos match option for IPv4 packets and the --ip6-class match option for IPv6 packets. To my understanding, those match the entire ToS or traffic class byte (i.e. the 6 DSCP bits and 2 ECN bits). To match DSCP specifically and ignore ECN bits, whatever they may be set to, I'd think a bitwise & would work, e.g. ToS byte of packet & 0xAC would match DSCP field 0x2B (0xAC being 0x2B << 2), but I don't think bitmasking is possible with the ebtables --ip-tos and --ip6-class options. Is it possible to match only the DSCP portion with ebtables?
Answering my own question, it doesn't seem that this is possible with ebtables (thank you for the comment @A.B), as there's no mask or specific keyword for dscp. Trying this in a legacy project that uses eb/iptables, but going to migrate to nft as there's a built-in dscp keyword that should work at the bridge layer.
Matching DSCP portion of ToS or traffic class byte using ebtables
1,515,464,161,000
I run a server with a web server running as a rootless podman container. This exposes ports 10080 and 10443 because, as a rootless container, it is not allowed to expose ports 80 and 443. So that my website can be accessed from outside, I use ufw as a firewall and have set up port forwarding there. To do this, I added the following lines to the beginning of the /etc/ufw/before.rules file: *nat :PREROUTING ACCEPT [0:0] -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 10080 -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 10443 COMMIT So far everything works. I now want to run another container that runs a Wireguard server. This outputs the following in its log and seems to set this as rules in the firewall: [#] ip link add wg0 type wireguard [#] wg setconf wg0 /dev/fd/63 [#] ip -4 address add 10.13.13.1 dev wg0 [#] ip link set mtu 1420 up dev wg0 [#] ip -4 route add 10.13.13.2/32 dev wg0 [#] iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth+ -j MASQUERADE If I run the Wireguard container without the ufw firewall activated - especially without the defined port forwarding - everything works. I can connect with a client and its traffic is routed through the tunnel and reaches the Internet. If, on the other hand, I activate the ufw firewall including the defined port forwarding and then connect to the Wireguard VPN with a client, then all page views seem to reach my server itself - at least I get error messages like this: This server could not prove that it is www.google.de. Its security certificate comes from <myServer>.de How can I configure the ufw firewall so that Requests from outside to port 80 or 443 are forwarded to ports 10080 or 10443 and thus reach my web server Requests from my vpn-client reach the Internet via the WireGuard tunnel and not my own server? (On another server I run the WebServer and WireGuard both under docker - everything works because the Docker WebServer directly exposes ports 80 and 443 and therefore I don't need any port forwarding.) Many thanks for your help.
After rethinking solution is simple: just do the port forwarding only when destination is my servers IP, so I changed before.rules to: *nat :PREROUTING ACCEPT [0:0] -A PREROUTING -d <ServerIP> -p tcp --dport 80 -j REDIRECT --to-port 10080 -A PREROUTING -d <ServerIP> -p tcp --dport 443 -j REDIRECT --to-port 10443 COMMIT
How to define port forwarding
1,693,265,506,000
I am trying to enable remotelogin on MacOS (Ventura). "sudo systemsetup -setremotelogin on" says it is already enabled (confirmed by the GUI), but if I try to login from my Linux PC I get % ssh [email protected] ssh: connect to host 10.42.100.13 port 22: Connection timed out Both system application firewall and packet filter have been disabled (temporarily). "Allow access for" has been set to "All users" in the preferences. Using tcpdump on the Macbook I see incoming traffic for destination port 22/tcp. The Mac doesn't answer. There is no problem for "ssh localhost" or "ssh 10.42.100.13" on the Mac itself. The Mac can ping my Linux PC without problems. Every helpful hint is highly appreciated.
My fault: System Integrity Protection was still off. After turning it on again I can login via ssh. Hope this is helpful for somebody out there running into the same pitfall.
how can I enable sshd on MacOS ventura, if "systemsetup -setremotelogin on" doesn't work?
1,693,265,506,000
I have Debian 11 using the new Firewall Daemon, and I have a device connected to eth1. I want to block all connections from internet or any IP other than the local IP in the range 10.147.20.0/24. Is it possible using firewall? I tried block zone, internal but i can still ping www.yahoo.com. [Update 1] eth0 -> connected to internet eth1 -> local devices ex. NAS tap1 -> VPN eth2 -> Update I want the following policy: tap1: should be able to surf through eth0 tap1: access eth1, eth2 eth1: communicate with tap1, eth2 eth2: communicate with tap1, eth1, eth0 to surf internet I have also put eth1, eth2, tap1 into the same bridge br0
I found a solution to my issue, in which i created a bridge br0, and masqueraded eth0 that has internet. In such a case any interface connected to br0 will be open to the internet. It is not a firewall issue rather than a network design issue. Solution: First masqueraded eth0 to pass internet. Second changed the bridge from using brctl into using openvswitch. Then i added a firewall on the openvswitch using openflow to disable eth1 from surfing the internet using this rule. ovs-ofctl add-flow br0 "priority=200,ip,nw_dst=192.168.188.0/24,in_port=eth1,actions=drop" Router address: 192.168.188.0/24
How to block connection from eth1 through firewall daemon?
1,693,265,506,000
I have a server with default deny and several UFW rules. UFW is enabled on startup (systemctl enable UFW). When I reboot only some of the rules don't get applied properly and I can't access some services. I can SSH into the server, and the lower ports (<1024) seem to work, but some services above 1024 still drop. If I execute ufw reload after a reboot, all begins to run fine. For example, I have port 3493 allowed for NUT-Server. Always after a reboot this port is non-responsive until I run ufw reload: 3493 ALLOW x.x.x.x/16 # nut-server (UPS) Oddly, however, the Monero port works: 18081 ALLOW x.x.x.x/24 # Monero When 3493 doesn't work, if I telnet into the machine with telnet x.x.x.x 3493 telnet just waits and never gets a response, indicating to me that the firewall is simply dropping the request, as per my default ufw default deny. Some other posts have pointed to iptables-persistent being the issue. I can confirm iptables-persistent and netfilter-persistent are purged from the system. journalctl -u ufw shows success: - - Boot f2ba2f00ebfe490f81680a3d43f695f2 -- Jan 23 09:54:15 cryptoDaemon systemd[1]: Finished Uncomplicated firewall. -- Boot cba07123c3204957ad3490a34d9d1439 -- Jan 23 10:00:45 cryptoDaemon systemd[1]: Finished Uncomplicated firewall. I can confirm ufw is enabled in /etc/ufw/ufw.conf UPDATE: To test I disabled ufw. Then, after a reboot I ran iptables -S. Oddly, there were rules. Any help getting this working consistently would be appreciated.
In this case I discovered there were entries in /etc/iptables.up.rules. In my case I believe iptables.up.rules existed because of an old edit in Webmin, which I also run. Moving /etc/iptables.up.rules to /etc/iptables.up.bak and rebooted. The issue is fixed. It turns out I had ifupdown installed and it was loading the firewall rules in /etc/iptables/up.rules. Disabling ifupdown with systemctl disable networking.service fixed the issue
UFW not fully loading rules on startup
1,693,265,506,000
The following two rules allow for passive transfers which i added as Firewall rules for my FTP server. //The following two rules allow the inbound FTP connection iptables -A INPUT -s $hostIP -p tcp --dport 21 -i eth0 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -A OUTPUT -d $hostIP -p tcp --sport 21 -o eth0 -m state --state ESTABLISHED -j ACCEPT // The following two rules allow for passive transfers iptables -A INPUT -s $hostIP -p tcp --dport 1024:65535 -i eth0 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -A OUTPUT -d $hostIP -p tcp --sport 1024:65535 -o eth0 -m state --state ESTABLISHED -j ACCEPT My FTP was server configured by assigning passive port to range "1024:65535" and above rules worked. But now FTP server configured to bind any free port instead fix port range. So what changes required in above two rules? Edit After applying three rules for passive FTP connection mentioned in answer i have rules in following order and now it's stopped working means client is connected but unable to retrieve remote directory. //The following two rules allow the inbound FTP connection iptables -A INPUT -s $hostIP -p tcp --dport 21 -i eth0 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -A OUTPUT -d $hostIP -p tcp --sport 21 -o eth0 -m state --state ESTABLISHED -j ACCEPT iptables -A PREROUTING -t raw -p tcp -s $hostIP --dport 21 -j CT --helper ftp iptables -A INPUT -m conntrack --ctstate RELATED -m helper --helper ftp -s $hostIP -p tcp -j ACCEPT iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED -m helper --helper ftp -d $hostIP -p tcp -j ACCEPT Working Rules iptables -A PREROUTING -t raw -p tcp -s $hostIP --dport 21 -j CT --helper ftp iptables -A INPUT -i eth0 -p tcp -s $hostIP -m conntrack --ctstate RELATED,ESTABLISHED -m helper --helper ftp -j ACCEPT iptables -A OUTPUT -o eth0 -p tcp -d $hostIP -m conntrack --ctstate ESTABLISHED -m helper --helper ftp -j ACCEPT
I assume $hostIP in your rules means a host you wish to allow FTP access for, otherwise your existing rules won't make sense to me. If you are using unencrypted FTP, you should replace your wide-open FTP data connection rules with connection tracking. First, add a rule that attaches a FTP connection tracking helper to any incoming FTP command connections: iptables -A PREROUTING -t raw -p tcp -s $hostIP --dport $ftpCMDport -d $ftpServerIP -j CT --helper ftp Here, $ftpCMDport is the port in which your local FTP server accepts logins; usually it's port 21. (Historical note: this used to happen automatically for TCP port 21, but it turned out the automatic assignment could be abused, so the automatic assignment of connection tracking helpers was made optional in Linux kernel 3.5, and later the automatic assignment feature was completely removed.) Once the FTP command connections are being monitored by the CT helper, the firewall will "know" which ports should be allowed for legitimate FTP data connections. You'll need two more rules to actually use this information to allow incoming data connections: iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -m helper \ --helper ftp -s $hostIP -d $ftpServerIP -p tcp -j ACCEPT iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -m helper \ --helper ftp -s $ftpServerIP -d $hostIP -p tcp -j ACCEPT Together, these three rules should entirely replace your existing two rules for FTP data connections. These should be good for both active and passive connections, should your FTP server allow both types. If you only want to accept passive FTP data connections, you might want to remove the RELATED in the OUTPUT rule. This was based on: https://home.regit.org/netfilter-en/secure-use-of-helpers/ If you are using SSL/TLS encrypted FTP, then the connection tracking helper won't be able to make sense of the encrypted FTP command traffic, and so if the FTP server will accept data connections in any free port, you cannot effectively firewall traffic by TCP ports at all, since any TCP port could become a FTP data port for some connection. Your only possibility would then be to limit traffic by IP addresses: iptables -A INPUT -s $hostIP -p tcp -i eth0 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -A OUTPUT -d $hostIP -p tcp -o eth0 -m state --state ESTABLISHED -j ACCEPT Note that these are essentially your existing rules, with the --dport and --sport options removed.
How to make Firewall rules for Passive FTP which uses dynamic port?
1,693,265,506,000
I want to connect to a remote computer and start Jupyter notebook on the remote computer. Every time I try to connect to jupyter notebook there is an error. When I turn off my firewall the jupyter notebook works. Is there any way to not turn off the firewall and get around this? My computer has windows and the remote computer has ubuntu installed
I assume that you are turning off the firewall on your client machine, you need to add a outbound rule to allow a SSH connection. If you are using Windows firewall then you can use the following command to add a outbound rule via command-line (CHANGE THE PORT YOU ARE USING FOR SSH ACCORDINGLY): netsh advfirewall firewall add rule name="Open SSH Port 22" dir=in action=allow protocol=TCP localport=22 remoteip=any as mentioned here by Krypton Razer. Alternatively you can also add this rule via GUI as stated in the documentation.
how to get around the firewall when connecting to the remote server
1,693,265,506,000
As follow is the list of the iptables rules that I have : # firewall-cmd --direct --get-all-rules ipv4 filter INPUT 0 -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT ... ... ipv4 filter INPUT 1 -d 127.0.0.1 -p tcp -m tcp --dport 4118 -j ACCEPT ipv4 filter INPUT 2 -i lo -j DROP ipv4 filter FORWARD 0 -j DROP ipv4 filter OUTPUT 0 -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT ... ... ipv4 filter OUTPUT 1 -d 127.0.0.1 -p tcp -m tcp --dport 4118 -j ACCEPT ipv4 filter OUTPUT 2 -o lo -j DROP When I start my dsa command I get the following erreur message : dsa_control couldn't connect to 127.0.0.1:4118 (-1: Socket reset) ss -ntl gives : State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:111 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:111 [::]:* LISTEN 0 5 *:4118 *:* LISTEN 0 128 [::]:22 [::]:* Everything works fine when I remove the DROP input and output rules. Any idea of how these DROP rules still block ip 127.0.0.1 ?
A rule was indeed missing. I had to add the option --dport in addition to --sport for the port to be open as needed.
iptables/firewall-cmd DROP rules set last block ip rule set before
1,693,265,506,000
Today I want to expose my cloud redis into public network, for some security reason, I just want my specific ip could access the redis port 6379. Now I do it in my cloud host like this: firewall-cmd --new-zone=special --permanent firewall-cmd --reload firewall-cmd --zone=special --add-source=61.173.91.1/32 --permanent firewall-cmd --zone=special --add-port=6379/tcp --permanent firewall-cmd --reload to my surprise, after I startup the firewalld service, I still not able to connect the redis service. My local public ip is: 61.173.91.244 where is going wrong and what should I do to make it work?
expand the ip range: firewall-cmd --zone=special --add-source=61.173.91.1/24 --permanent works.
why the firewalld add port and ip witle list not working as expect
1,620,033,444,000
I'm connected via PuTTY ssh to a Linux Server (so it's not supposed to have a GUI). when I npm install something, due to some intranet network configuration, the http request is redirected as follows npm i express npm WARN registry Unexpected warning for http://registry.npmjs.org/: Miscellaneous Warning SELF_SIGNED_CERT_IN_CHAIN: request to https://auth-fw-dc.mycompany.com:nnnn/php/uid.php?...&url=http://registry.npmjs.org%2fexpress failed Of course the SELF_SIGNED_CERT_IN_CHAIN derives from the redirection to our firewall authentication web portal. I guess it is a wrong network configuration in our intranet and the http request from npm should not be redirected to our company's firewall especially because I can't open a browser from ssh to authenticate myself there: am I guessing right or is it something I can configure on this machine with some SSH Linux commands for npm?
Apparently solved after clearing the npm cache rm ./package-lock.json rm -r ./node_modules npm cache clear --force and having reconfigured the https connection but without check. npm set strict-ssl false and npm config set registry https://registry.npmjs.org/ or equivalently npm config rm registry (not sure if anything else was done by the network team after I wrote to them) In conclusion, in my intranet scenario, the issue was due to the following http setting (initial tried to circumvent the ssl issue, see for example SO) npm config set registry http://registry.npmjs.org/ and solved by removing that wrong command, as said above.
authentication for npm install during PuTTY ssh?
1,620,033,444,000
I added a large number of domains to my /etc/hosts, in the hope of preventing outgoing traffic to those sites. Now I have found however that my /etc/hosts is having no effect. It's meant to serve as a primitive outgoing firewall. Does anyone know why these would have no effect at all? 127.0.0.1 a.ns.facebook.com 127.0.0.1 b.ns.facebook.com 127.0.0.1 c.ns.facebook.com 127.0.0.1 d.ns.facebook.com 127.0.0.1 doubleclick.net 127.0.0.1 edge-star-mini-shv-01-any2.facebook.com 127.0.0.1 edge-star-mini-shv-01-atl3.facebook.com 127.0.0.1 securepubads.g.doubleclick.net 127.0.0.1 twitter.com 127.0.0.1 twimg.com 127.0.0.1 abs.twimg.com 127.0.0.1 pbs.twimg.com 127.0.0.1 apps.facebook.com 127.0.0.1 connect.facebook.net 127.0.0.1 facebook.com 127.0.0.1 fbcdn.com 127.0.0.1 fbsbx.com 127.0.0.1 fbcdn.net 127.0.0.1 graph.facebook.com 127.0.0.1 login.facebook.com 127.0.0.1 s-static.ak.facebook.com 127.0.0.1 static.ak.connect.facebook.com 127.0.0.1 static.ak.fbcdn.net 127.0.0.1 www.connect.facebook.net 127.0.0.1 www.facebook.com 127.0.0.1 www.fbcdn.com 127.0.0.1 www.fbcdn.net 127.0.0.1 www.graph.facebook.com 127.0.0.1 www.login.facebook.com 127.0.0.1 www.s-static.ak.facebook.com 127.0.0.1 www.static.ak.connect.facebook.com 127.0.0.1 www.static.ak.fbcdn.net 127.0.0.1 0-edge-chat.facebook.com 127.0.0.1 1-edge-chat.facebook.com 127.0.0.1 2-edge-chat.facebook.com 127.0.0.1 3-edge-chat.facebook.com 127.0.0.1 4-edge-chat.facebook.com 127.0.0.1 5-edge-chat.facebook.com 127.0.0.1 6-edge-chat.facebook.com 127.0.0.1 alpha-shv-03-ash5.facebook.com 127.0.0.1 alpha-shv-03-atn1.facebook.com 127.0.0.1 alpha-shv-03-lla1.facebook.com 127.0.0.1 alpha-shv-04-prn2.facebook.com 127.0.0.1 alpha-shv-09-frc1.facebook.com 127.0.0.1 alpha.vvv.facebook.com 127.0.0.1 a.ns.facebook.com 127.0.0.1 api.facebook.com 127.0.0.1 atlasalpha-shv-09-frc3.facebook.com 127.0.0.1 atlas.c10r.facebook.com 127.0.0.1 atlasinyour-shv-05-ash3.facebook.com 127.0.0.1 atlas-shv-01-prn2.facebook.com 127.0.0.1 atlas-shv-04-lla1.facebook.com 127.0.0.1 atlas-shv-05-ash3.facebook.com 127.0.0.1 atlas-shv-06-ash2.facebook.com 127.0.0.1 atlas-shv-06-frc1.facebook.com 127.0.0.1 atlas-shv-07-lla1.facebook.com 127.0.0.1 atlas-shv-09-frc3.facebook.com 127.0.0.1 atlas-shv-13-prn1.facebook.com 127.0.0.1 atlas-www-shv-04-prn2.facebook.com 127.0.0.1 atlas-www-shv-07-ash4.facebook.com 127.0.0.1 atlas-www-shv-09-frc1.facebook.com 127.0.0.1 aura-11-01-snc7.facebook.com 127.0.0.1 badge.facebook.com 127.0.0.1 b-api.facebook.com 127.0.0.1 beta-chat-01-05-ash3.facebook.com 127.0.0.1 betanet-shv-03-atn1.facebook.com 127.0.0.1 betanet-shv-03-lla1.facebook.com 127.0.0.1 betanet-shv-04-prn2.facebook.com 127.0.0.1 betanet-shv-09-frc1.facebook.com 127.0.0.1 beta-shv-03-atn1.facebook.com 127.0.0.1 beta-shv-03-lla1.facebook.com 127.0.0.1 beta-shv-04-prn2.facebook.com 127.0.0.1 beta-shv-09-frc1.facebook.com 127.0.0.1 beta.vvv.facebook.com 127.0.0.1 b-graph.facebook.com 127.0.0.1 bidder-shv-05-frc3.facebook.com 127.0.0.1 bidder-shv-10-frc1.facebook.com 127.0.0.1 b.ns.facebook.com 127.0.0.1 channel-proxy-shv-04-frc3.facebook.com 127.0.0.1 channel-proxy-shv-06-ash2.facebook.com 127.0.0.1 channel-proxy-shv-07-ash2.facebook.com 127.0.0.1 channel-proxy-shv-13-prn1.facebook.com 127.0.0.1 channel-proxy-test-shv-07-ash2.facebook.com 127.0.0.1 code.facebook.com 127.0.0.1 connect.facebook.com 127.0.0.1 dev.vvv.facebook.com 127.0.0.1 d.vvv.facebook.com 127.0.0.1 edge-atlas-proxyprotocol-shv-01-ash5.facebook.com 127.0.0.1 edge-atlas-proxyprotocol-shv-03-ash5.facebook.com 127.0.0.1 edge-atlas-proxyprotocol-shv-07-ash4.facebook.com 127.0.0.1 edge-atlas-proxyprotocol-shv-07-frc3.facebook.com 127.0.0.1 edge-atlas-proxyprotocol-shv-09-frc1.facebook.com 127.0.0.1 edge-atlas-proxyprotocol-shv-12-frc1.facebook.com 127.0.0.1 edge-atlas-proxyprotocol-shv-12-frc3.facebook.com 127.0.0.1 edge-atlas-proxyprotocol-shv-13-frc1.facebook.com 127.0.0.1 edge-atlas-shv-01-ams2.facebook.com 127.0.0.1 edge-atlas-shv-01-ams3.facebook.com 127.0.0.1 edge-atlas-shv-01-ash5.facebook.com 127.0.0.1 edge-atlas-shv-01-atl1.facebook.com 127.0.0.1 edge-atlas-shv-01-bru2.facebook.com 127.0.0.1 edge-atlas-shv-01-cai1.facebook.com 127.0.0.1 edge-atlas-shv-01-cdg2.facebook.com 127.0.0.1 edge-atlas-shv-01-dfw1.facebook.com 127.0.0.1 edge-atlas-shv-01-fra3.facebook.com 127.0.0.1 edge-atlas-shv-01-gru1.facebook.com 127.0.0.1 edge-atlas-shv-01-hkg2.facebook.com 127.0.0.1 edge-atlas-shv-01-iad3.facebook.com 127.0.0.1 edge-atlas-shv-01-kul1.facebook.com 127.0.0.1 edge-atlas-shv-01-lax1.facebook.com 127.0.0.1 edge-atlas-shv-01-lga1.facebook.com 127.0.0.1 edge-atlas-shv-01-lhr3.facebook.com 127.0.0.1 edge-atlas-shv-01-mad1.facebook.com 127.0.0.1 edge-atlas-shv-01-mia1.facebook.com 127.0.0.1 edge-atlas-shv-01-mxp1.facebook.com 127.0.0.1 edge-atlas-shv-01-nrt1.facebook.com 127.0.0.1 edge-atlas-shv-01-ord1.facebook.com 127.0.0.1 edge-atlas-shv-01-sea1.facebook.com 127.0.0.1 edge-atlas-shv-01-sin1.facebook.com 127.0.0.1 edge-atlas-shv-01-sjc2.facebook.com 127.0.0.1 edge-atlas-shv-01-syd1.facebook.com 127.0.0.1 edge-atlas-shv-01-vie1.facebook.com 127.0.0.1 edge-atlas-shv-02-cai1.facebook.com 127.0.0.1 edge-atlas-shv-02-hkg2.facebook.com 127.0.0.1 edge-atlas-shv-03-ash5.facebook.com 127.0.0.1 edge-atlas-shv-03-atn1.facebook.com 127.0.0.1 edge-atlas-shv-03-hkg1.facebook.com 127.0.0.1 edge-atlas-shv-03-lla1.facebook.com 127.0.0.1 edge-atlas-shv-03-prn2.facebook.com 127.0.0.1 edge-atlas-shv-03-xdc1.facebook.com 127.0.0.1 edge-atlas-shv-04-hkg1.facebook.com 127.0.0.1 edge-atlas-shv-04-prn2.facebook.com 127.0.0.1 edge-atlas-shv-06-atn1.facebook.com 127.0.0.1 edge-atlas-shv-06-lla1.facebook.com 127.0.0.1 edge-atlas-shv-07-ash4.facebook.com 127.0.0.1 edge-atlas-shv-09-frc1.facebook.com 127.0.0.1 edge-atlas-shv-09-lla1.facebook.com 127.0.0.1 edge-atlas-shv-12-frc1.facebook.com 127.0.0.1 edge-atlas-shv-12-frc3.facebook.com 127.0.0.1 edge-atlas-shv-12-lla1.facebook.com 127.0.0.1 edge-atlas-shv-12-prn1.facebook.com 127.0.0.1 edge-atlas-shv-13-frc1.facebook.com 127.0.0.1 edge-atlas-shv-17-prn1.facebook.com 127.0.0.1 edge-atlas-shv-18-prn1.facebook.com 127.0.0.1 edge-chat.facebook.com 127.0.0.1 edge-liverail-shv-01-ams2.facebook.com 127.0.0.1 edge-liverail-shv-01-ams3.facebook.com 127.0.0.1 edge-liverail-shv-01-ash5.facebook.com 127.0.0.1 edge-liverail-shv-01-atl1.facebook.com 127.0.0.1 edge-liverail-shv-01-bru2.facebook.com 127.0.0.1 edge-liverail-shv-01-cai1.facebook.com 127.0.0.1 edge-liverail-shv-01-cdg2.facebook.com 127.0.0.1 edge-liverail-shv-01-dfw1.facebook.com 127.0.0.1 edge-liverail-shv-01-fra3.facebook.com 127.0.0.1 edge-liverail-shv-01-gru1.facebook.com 127.0.0.1 edge-liverail-shv-01-hkg2.facebook.com 127.0.0.1 edge-liverail-shv-01-iad3.facebook.com 127.0.0.1 edge-liverail-shv-01-kul1.facebook.com 127.0.0.1 edge-liverail-shv-01-lax1.facebook.com 127.0.0.1 edge-liverail-shv-01-lga1.facebook.com 127.0.0.1 edge-liverail-shv-01-lhr3.facebook.com 127.0.0.1 edge-liverail-shv-01-mad1.facebook.com 127.0.0.1 edge-liverail-shv-01-mia1.facebook.com 127.0.0.1 edge-liverail-shv-01-mxp1.facebook.com 127.0.0.1 edge-liverail-shv-01-nrt1.facebook.com 127.0.0.1 edge-liverail-shv-01-ord1.facebook.com 127.0.0.1 edge-liverail-shv-01-sea1.facebook.com 127.0.0.1 edge-liverail-shv-01-sin1.facebook.com 127.0.0.1 edge-liverail-shv-01-sjc2.facebook.com 127.0.0.1 edge-liverail-shv-01-syd1.facebook.com 127.0.0.1 edge-liverail-shv-01-tpe1.facebook.com 127.0.0.1 edge-liverail-shv-01-vie1.facebook.com 127.0.0.1 edge-liverail-shv-02-cai1.facebook.com 127.0.0.1 edge-liverail-shv-02-hkg2.facebook.com 127.0.0.1 edge-liverail-shv-03-ash5.facebook.com 127.0.0.1 edge-liverail-shv-03-atn1.facebook.com 127.0.0.1 edge-liverail-shv-03-hkg1.facebook.com 127.0.0.1 edge-liverail-shv-03-lla1.facebook.com 127.0.0.1 edge-liverail-shv-03-prn2.facebook.com 127.0.0.1 edge-liverail-shv-03-xdc1.facebook.com 127.0.0.1 edge-liverail-shv-04-hkg1.facebook.com 127.0.0.1 edge-liverail-shv-04-prn2.facebook.com 127.0.0.1 edge-liverail-shv-06-atn1.facebook.com 127.0.0.1 edge-liverail-shv-06-lla1.facebook.com 127.0.0.1 edge-liverail-shv-07-ash4.facebook.com 127.0.0.1 edge-liverail-shv-07-frc3.facebook.com 127.0.0.1 edge-liverail-shv-09-frc1.facebook.com 127.0.0.1 edge-liverail-shv-09-lla1.facebook.com 127.0.0.1 edge-liverail-shv-12-frc1.facebook.com 127.0.0.1 edge-liverail-shv-12-frc3.facebook.com 127.0.0.1 edge-liverail-shv-12-lla1.facebook.com 127.0.0.1 edge-liverail-shv-12-prn1.facebook.com 127.0.0.1 edge-liverail-shv-13-frc1.facebook.com 127.0.0.1 edge-liverail-shv-17-prn1.facebook.com 127.0.0.1 edge-liverail-shv-18-prn1.facebook.com 127.0.0.1 edge-mqtt.facebook.com 127.0.0.1 edge-mqtt-shv-01-ams2.facebook.com 127.0.0.1 edge-mqtt-shv-01-ams3.facebook.com 127.0.0.1 edge-mqtt-shv-01-ash5.facebook.com 127.0.0.1 edge-mqtt-shv-01-atl1.facebook.com 127.0.0.1 edge-mqtt-shv-01-bru2.facebook.com 127.0.0.1 edge-mqtt-shv-01-cai1.facebook.com 127.0.0.1 edge-mqtt-shv-01-cdg2.facebook.com 127.0.0.1 edge-mqtt-shv-01-dfw1.facebook.com 127.0.0.1 edge-mqtt-shv-01-fra3.facebook.com 127.0.0.1 edge-mqtt-shv-01-gru1.facebook.com 127.0.0.1 edge-mqtt-shv-01-hkg2.facebook.com 127.0.0.1 edge-mqtt-shv-01-iad3.facebook.com 127.0.0.1 edge-mqtt-shv-01-kul1.facebook.com 127.0.0.1 edge-mqtt-shv-01-lax1.facebook.com 127.0.0.1 edge-mqtt-shv-01-lga1.facebook.com 127.0.0.1 edge-mqtt-shv-01-lhr3.facebook.com 127.0.0.1 edge-mqtt-shv-01-mad1.facebook.com 127.0.0.1 edge-mqtt-shv-01-mia1.facebook.com 127.0.0.1 edge-mqtt-shv-01-mxp1.facebook.com 127.0.0.1 edge-mqtt-shv-01-nrt1.facebook.com 127.0.0.1 edge-mqtt-shv-01-ord1.facebook.com 127.0.0.1 edge-mqtt-shv-01-sea1.facebook.com 127.0.0.1 edge-mqtt-shv-01-sin1.facebook.com 127.0.0.1 edge-mqtt-shv-01-sjc2.facebook.com 127.0.0.1 edge-mqtt-shv-01-syd1.facebook.com 127.0.0.1 edge-mqtt-shv-01-tpe1.facebook.com 127.0.0.1 edge-mqtt-shv-01-vie1.facebook.com 127.0.0.1 edge-mqtt-shv-02-cai1.facebook.com 127.0.0.1 edge-mqtt-shv-02-hkg2.facebook.com 127.0.0.1 edge-mqtt-shv-03-ash5.facebook.com 127.0.0.1 edge-mqtt-shv-03-atn1.facebook.com 127.0.0.1 edge-mqtt-shv-03-hkg1.facebook.com 127.0.0.1 edge-mqtt-shv-03-lla1.facebook.com 127.0.0.1 edge-mqtt-shv-03-prn2.facebook.com 127.0.0.1 edge-mqtt-shv-03-xdc1.facebook.com 127.0.0.1 edge-mqtt-shv-04-hkg1.facebook.com 127.0.0.1 edge-mqtt-shv-04-prn2.facebook.com 127.0.0.1 edge-mqtt-shv-06-atn1.facebook.com 127.0.0.1 edge-mqtt-shv-06-lla1.facebook.com 127.0.0.1 edge-mqtt-shv-07-ash4.facebook.com 127.0.0.1 edge-mqtt-shv-07-frc3.facebook.com 127.0.0.1 edge-mqtt-shv-09-lla1.facebook.com 127.0.0.1 edge-mqtt-shv-12-frc1.facebook.com 127.0.0.1 edge-mqtt-shv-12-frc3.facebook.com 127.0.0.1 edge-mqtt-shv-12-lla1.facebook.com 127.0.0.1 edge-mqtt-shv-12-prn1.facebook.com 127.0.0.1 edge-mqtt-shv-13-frc1.facebook.com 127.0.0.1 edge-mqtt-shv-17-prn1.facebook.com 127.0.0.1 edge-mqtt-shv-18-prn1.facebook.com 127.0.0.1 edgeray-origin-shv-05-prn2.facebook.com 127.0.0.1 edgeray-origin-shv-07-lla1.facebook.com 127.0.0.1 edgeray-origin-shv-09-frc3.facebook.com 127.0.0.1 edgeray-origin-shv-11-frc3.facebook.com 127.0.0.1 edgeray-shv-01-ams2.facebook.com 127.0.0.1 edgeray-shv-01-ams3.facebook.com 127.0.0.1 edgeray-shv-01-atl1.facebook.com 127.0.0.1 edgeray-shv-01-bru2.facebook.com 127.0.0.1 edgeray-shv-01-cdg2.facebook.com 127.0.0.1 edgeray-shv-01-dfw1.facebook.com 127.0.0.1 edgeray-shv-01-fra3.facebook.com 127.0.0.1 edgeray-shv-01-gru1.facebook.com 127.0.0.1 edgeray-shv-01-iad3.facebook.com 127.0.0.1 edgeray-shv-01-kul1.facebook.com 127.0.0.1 edgeray-shv-01-lax1.facebook.com 127.0.0.1 edgeray-shv-01-lga1.facebook.com 127.0.0.1 edgeray-shv-01-lhr3.facebook.com 127.0.0.1 edgeray-shv-01-mad1.facebook.com 127.0.0.1 edgeray-shv-01-mia1.facebook.com 127.0.0.1 edgeray-shv-01-mxp1.facebook.com 127.0.0.1 edgeray-shv-01-ord1.facebook.com 127.0.0.1 edgeray-shv-01-sea1.facebook.com 127.0.0.1 edgeray-shv-01-sin1.facebook.com 127.0.0.1 edgeray-shv-01-sjc2.facebook.com 127.0.0.1 edgeray-shv-01-syd1.facebook.com 127.0.0.1 edgeray-shv-01-vie1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-ams3.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-atl1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-bru2.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-cai1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-cdg2.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-dfw1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-fra3.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-gru1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-iad3.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-kul1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-lax1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-lhr3.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-mad1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-nrt1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-ord1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-sea1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-01-syd1.facebook.com 127.0.0.1 edge-snaptu-http-p1-shv-02-cai1.facebook.com 127.0.0.1 edge-snaptu-tunnel-shv-01-ams3.facebook.com 127.0.0.1 edge-snaptu-tunnel-shv-01-ash5.facebook.com 127.0.0.1 edge-snaptu-tunnel-shv-01-atl1.facebook.com 127.0.0.1 edge-snaptu-tunnel-shv-01-bru2.facebook.com 127.0.0.1 edge-snaptu-tunnel-shv-01-cai1.facebook.com
One approach, in the absence of a decent application firewall, is: Identify an IP range that needs blocking e.g. a range that is associated with an unfriendly server. Add a firewall rule to block all outgoing traffic to that range. This at least works.
My /etc/hosts is having no effect