date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,614,612,997,000 |
I am using a Ubuntu machine as a NAT router. How can I find out the following:
the ports on which the LAN machines are listening or communicating (both tcp and udp);
which local machines have established connections with which WAN ip's on those ports;
and the size of data that has been transfered on those ports.
|
I think you want to try netstat-nat I seem to remember using it when I had a Slackware box set up as a NAT-server.
| Port monitoring on GNU/Linux based NAT router |
1,614,612,997,000 |
I'm just beginning to dig into iptables for the first time today, so apologies for any naivete.
For reference, I'm using
Ubuntu 22.04.4 LTS (Jammy Jellyfish)
iptables v1.8.7 (nf_tables)
ufw 0.36.1
Now, I know (or, rather, recently learned) that ufw is just a wrapper for iptables. I decided I wanted to understand what was going on underneath the hood, so I started reading and poking around. What I can't seem to understand is how iptables deals with packets in conjunction with ufw. Let's start with the INPUT chain, which is I believe where any incoming packet would start.
Chain INPUT (policy DROP)
target prot opt source destination
ufw-before-logging-input all -- anywhere anywhere
ufw-before-input all -- anywhere anywhere
ufw-after-input all -- anywhere anywhere
ufw-after-logging-input all -- anywhere anywhere
ufw-reject-input all -- anywhere anywhere
ufw-track-input all -- anywhere anywhere
I feel like if I'm understanding everything correctly, then this first line here ufw-before-logging-input all -- anywhere anywhere means that any packet that comes in, on any port, from anywhere, will be passed along to the ufw-before-logging-input chain. If it comes back from that chain without being accepted, dropped, or rejected, then it'll be passed on to the next chain, in this case ufw-before-input, and so on and so forth, until it's accepted, dropped, or rejected (viz., until it encounters a terminating action).
Okay, so let's look at the first chain any packet will be passed along to, ufw-before-logging-input.
Chain ufw-before-logging-input (1 references)
target prot opt source destination
Literally nothing here, so we move on to the ufw-before-input chain
Chain ufw-before-input (1 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ufw-logging-deny all -- anywhere anywhere ctstate INVALID
DROP all -- anywhere anywhere ctstate INVALID
ACCEPT udp -- anywhere anywhere udp spt:bootps dpt:bootpc
ufw-not-local all -- anywhere anywhere
ACCEPT udp -- anywhere host.name udp dpt:mdns
ACCEPT udp -- anywhere w.x.y.z udp dpt:num
ufw-user-input all -- anywhere anywhere
And this is where I'm confused. The very first line looks like we just accept any packet at all ACCEPT all -- anywhere anywhere but.... my firewall rules work, they block traffic.
So, what am I missing, here?
(Note, tried to post this on Stackoverflow, but they sent me here. Just including this in case you Google it and see this is duplicated elsewhere.)
|
So, what am I missing, here?
The -v option for verbose:
-v, --verbose
Verbose output. This option makes the list command show the
interface name, the rule options (if any), and the TOS masks. The
packet and byte counters are also listed, [...]
You probably used something like:
# iptables -L ufw-before-input
Chain ufw-before-input (1 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ufw-logging-deny all -- anywhere anywhere ctstate INVALID
DROP all -- anywhere anywhere ctstate INVALID
[...]
which won't display interfaces. Instead with -v:
# iptables -v -L ufw-before-input
Chain ufw-before-input (1 references)
pkts bytes target prot opt in out source destination
6 504 ACCEPT all -- lo any anywhere anywhere
12 1032 ACCEPT all -- any any anywhere anywhere ctstate RELATED,ESTABLISHED
0 0 ufw-logging-deny all -- any any anywhere anywhere ctstate INVALID
0 0 DROP all -- any any anywhere anywhere ctstate INVALID
[...]
One can see the ACCEPT rule is for input interface lo: to allow inconditionally loopback traffic, and only from the lo interface. Anything else continues chain traversal.
Anyway this format isn't really suitable for reproducibility especially when displaying a ruleset in a Q/A. It might still be useful to check status of special (eg: with memorized state) matches or targets. Better use either iptables -S or iptables-save (for the whole ruleset or at least a whole table).
# iptables -S ufw-before-input
-N ufw-before-input
-A ufw-before-input -i lo -j ACCEPT
-A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny
-A ufw-before-input -m conntrack --ctstate INVALID -j DROP
[...]
iptables -S can also accept the -v option to display counters among other states. Likewise to display counters with iptables-save use iptables-save -c. iptables-save is intended to provide an output suitable for iptables-restore allowing to save and restore rulesets. Also using twice -v (eg: -vv) with iptables displays additional debug information.
| Tracing iptables Rules |
1,614,612,997,000 |
Flowtables is an nftables feature for offloading traffic to a "fast path" that skips the typical forwarding path once a connection is established. Two things need to be configured to set up flowtables. First is the flowtable itself, which is defined as part of a table. Second is a flow offload statement, and this is what my question is about. The nft man page says:
FLOW STATEMENT
A flow statement allows us to select what flows you want to accelerate
forwarding through layer 3 network stack bypass. You have to specify
the flowtable name where you want to offload this flow.
flow add @flowtable
The wiki page includes this full configuration example:
table inet x {
flowtable f {
hook ingress priority 0; devices = { eth0, eth1 };
}
chain forward {
type filter hook forward priority 0; policy drop;
# offload established connections
ip protocol { tcp, udp } flow offload @f
ip6 nexthdr { tcp, udp } flow offload @f
counter packets 0 bytes 0
# established/related connections
ct state established,related counter accept
# allow initial connection
ip protocol { tcp, udp } accept
ip6 nexthdr { tcp, udp } accept
}
}
Here's where I get confused. The example uses the same condition (ip protocol { tcp, udp }) to both accept the traffic and to flow offload it. Is that because flow offload will implicitly accept a flow by adding it to the flowtable, meaning those conditions should always match? Or is it just a coincidence in this example, and the accept rule could be more restrictive?
Concretely, suppose I only want to forward SSH traffic inbound from eth0, and I want to enable flow offloading. Should I configure the forward chain like this?
chain forward {
type filter hook forward priority 0; policy drop;
# offload established connections
ip protocol { tcp, udp } flow offload @f
# established/related connections
ct state established,related counter accept
# allow initial connection
iif eth0 tcp dport 22 accept
}
Or like this? (only the flow offload rule has changed)
chain forward {
type filter hook forward priority 0; policy drop;
# offload established connections
iif eth0 tcp dport 22 flow offload @f
# established/related connections
ct state established,related counter accept
# allow initial connection
iif eth0 tcp dport 22 accept
}
|
There are a few key sentences that I first want to point out from the wiki:
You can select which flows you want to offload through the flow
expression from the forward chain.
Flows are offloaded after the state is created. That means that
usually the first reply packet will create the flowtable entry. A
firewall rule to accept the initial traffic is required. The flow
expression on the forward chain must match the return traffic of the
initial connection.
Getting even more specific, it points out:
This also means if you are using special ip rules, you need to make
sure that they match the reply packet traffic as well as the original
traffic.
I found in my experiences with it, working out reply direction, estab or not, initial etc was just too hard.
Also from their example, pay close attention to their comments; the flow statement offloads established, and further down you must accept the initial connection(s).
Offloading in general is a good thing IMO, so I just use a broad flow statement like this:
ip6 nexthdr { tcp, udp } flow add @f counter
ip protocol { tcp, udp } flow add @f counter
And then I allow out and in as normal:
ct state established,related counter accept
iif $DEV_INSIDE counter accept
iif $DEV_OUTSIDE ip6 daddr <mail server> tcp dport { smtp } counter accept
The flow statement definitely does not just accept everything, although it looks that way. Look at their ASCII diagram above and it should make more sense.
Pablo Neira Ayuso put it a slightly different way:
The 'flow offload' action adds the flow entry once the flow is in
established state, according to the connection tracking definition, ie.
we have seen traffic in both directions. Therefore, only initial packets
of the flow follow the classic forwarding path.
So in summary, yes, you could get more specific in the flow add statements, but why bother when ultimately, flows follow ESTAB state, and you can maintain protection with normal, stateful rules elsewhere.
This resource is also quite in-depth and awesome.
I would go with your first example, and just double-check with an nmap scan. Also note that you can then check for success using conntrack -L.
| How should `flow offload` statements be configured when using flowtables? |
1,614,612,997,000 |
Is there anything I could I execute from a linux command line from 2 different linux clients, in 2 different locations, that may show the presence of absence of an ERR_CONNECTION_RESET message (or similar) in the output of the connection attempt? I'd like to know if there's a way I can do this when attempting the connection via either the domain or full URI using https.
(My understanding is that an ERR_CONNECTION_RESET can be an indicator that a connection is failing due to a blocking firewall. I'm trying to establish whether there's a potential blocking firewall for a resource, when using one connection path compared to another).
|
The curl command will have an exit code of 56 when a connection reset by peer happens:
56 Failure in receiving network data.
curl http://someurl/
$ curl http://192.0.2.2:8080/
unfinished data...
curl: (56) Recv failure: Connection reset by peer
$ echo $?
56
There's no guarantee (from the documentation) that 56 is only caused by Connection reset by peer or even that Connection reset by peer can only exit with 56, but one can also filter the error on stderr like this (2>&1 is placed first on purpose):
LANG=C curl --no-progress-meter http://someurl/ 2>&1 >/dev/null |
grep -Fq 'Connection reset by peer' && echo RST || echo non-RST
which would print RST for a Connection reset by peer and non-RST for anything else (including success).
It would be a brittle thing to use for production (this string could appear as header data etc.), but as it's for debugging a specific problem...
| Is there something I can execute via the CLI, to show the presence or absence of an ERR_CONNECTION_RESET when attempting connection to a domain/URI? |
1,614,612,997,000 |
I'd like to take a default drop approach to my firewall rules. I've created some rules for testing purposes:
table bridge vmbrfilter {
chain forward {
type filter hook forward priority -100; policy drop;
ip saddr 192.168.1.10 ip daddr 192.168.1.1 accept;
ip saddr 192.168.1.1 ip daddr 192.168.1.10 accept;
}
}
However traffic between 192.168.1.1 and 192.168.1.10 is still blocked. To see if it is a syntax issue, I tried:
table bridge vmbrfilter {
chain forward {
type filter hook forward priority -100; policy accept;
ip saddr 192.168.1.10 ip daddr 192.168.1.1 drop;
ip saddr 192.168.1.1 ip daddr 192.168.1.10 drop;
}
}
This however succeeds in blocking traffic between the two IPs. So I don't have a clue as to why my accept rules aren't being hit. The nftables wiki says:
The drop verdict means that the packet is discarded if the packet
reaches the end of the base chain.
But I literally have accept rules in my chain which should be matching.
Have I not understood something correctly? Thanks in advance for any help.
Update: A.B's ARP rule suggestion is helping. However I've discovered that my VLAN tagging is causing issues with my firewall rules. The ARP rule allows tagged traffic in through the physical NIC, the ARP replies are making it over the bridge but get blocked on exit from the physical NIC.
|
IPv4 over Ethernet relies on ARP to resolve the Ethernet MAC address of the peer in order to send later unicast packets to it.
As you're filtering any ARP request since there's no exception for it, those requests can't succeed and after a typical 3s timeout you'll get the standard "No route to host". There won't be any IPv4 packet sent from 192.168.1.10 to 192.168.1.1 or from 192.168.1.1 to 192.168.1.10, since the previous step failed.
So add this rule for now, and see later how to fine-tune it if you really need:
nft add rule bridge vmbrfilter forward ether type arp accept
If the bridge is VLAN aware (vlan_filtering=1) or probably even if not (ie: a bridge manipulating frames and not really knowing more about them, which is probably not good if two frames from two different VLANs have the same MAC address) then here's a rule to allow ARP packets within VLAN tagged frames:
nft add rule bridge vmbrfilter forward ether type vlan vlan type arp accept
But anyway, IP will have the same kind of problem without adaptation. This requires more information of the VLAN setup.
Here's a ruleset allowing tagged and non tagged frames alike, requiring duplication of rules. ARP having no further expression to filter it thus auto-selecting the protocol/type, it requires an explicit vlan type arp.
table bridge vmbrfilter # for idempotency
delete table bridge vmbrfilter # for idempotency
table bridge vmbrfilter {
chain forward {
type filter hook forward priority -100; policy drop;
ip saddr 192.168.1.10 ip daddr 192.168.1.1 accept
ip saddr 192.168.1.1 ip daddr 192.168.1.10 accept
ether type arp accept
ether type vlan ip saddr 192.168.1.10 ip daddr 192.168.1.1 accept
ether type vlan ip saddr 192.168.1.1 ip daddr 192.168.1.10 accept
ether type vlan vlan type arp accept
}
}
Also older versions of nftables (eg: OP's 0.9.0) might omit mandatory filter expressions in the output when they don't have additional filters (eg, but not present in this answer: ether type vlan arp htype 1 (display truncated) vs vlan id 10 arp htype 1) , so their output should not be reused as input in configuration files. One can still tell the difference and know the additional filter expression is there by using nft -a --debug=netlink list ruleset.
As far as I know there's no support yet for arbitrary encapsulation/decapsulation of protocols in nftables, so duplication of rules appears unavoidable (just look at the bytecode to see how same fields are looked up for the VLAN and non-VLAN cases: different offset).
| Nftables default drop chain problem |
1,614,612,997,000 |
I am using iptables recent module:
-A INPUT -m recent --rsource --name PORTSCAN --set -j DROP
The above line adds offending IP addresses to /proc/net/xt_recent/PORTSCAN.
Now I am looking for a way how to periodically (cron job) check this list, and remove entries that are older than n hours.
I am using the option xt_recent.ip_pkt_list_tot=1 with recent. That means, I don't keep multiple times when packet was seen. I only keep the last time packet was seen.
So the list /proc/net/xt_recent/PORTSCAN looks like this:
src=185.242.5.46 ttl: 240 last_seen: 4312349727 oldest_pkt: 1 4312349727
src=184.100.29.188 ttl: 57 last_seen: 4312673918 oldest_pkt: 1 4312673918
src=184.157.25.107 ttl: 57 last_seen: 4312086204 oldest_pkt: 1 4312086204
How can I periodically "purge" this list, so that I only keep entries that are less than n hours old?
Does iptables provide some way to do this? Or does this have to me done with some custom script?
|
It looks like --reap is what you are looking for, from iptables-extensions man page, section about recent:
--reap
This option can only be used in conjunction with --seconds. When used, this will cause entries older than the last given number of seconds to be purged.
As of how it works, here is the relevant source code part from Linux kernel.
| iptables recent module: remove entries older than |
1,614,612,997,000 |
I'm running Gentoo Linux, so using plain iptbales to manage my firewall and networking.
I usually use wan0 for all my traffic, but since I have already a web-server behind that i would like wan1 (bind to another domain) for my second web-server.
I have three interfaces:
eth0 = LAN
wan0 = Primary used WAN (default gateway)
wan1 = Secondary WAN
Some Infos about the Gateways
> route -n
Kernel IP Routentabelle
Ziel Router Genmask Flags Metric Ref Use Iface
0.0.0.0 80.108.x.x 0.0.0.0 UG 0 0 0 wan0
192.168.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
80.108.x.0 0.0.0.0 255.255.254.0 U 0 0 0 wan0
84.114.y.0 0.0.0.0 255.255.255.0 U 0 0 0 wan1
127.0.0.0 127.0.0.1 255.0.0.0 UG 0 0 0 lo
The default init for NAT/MASQUEARDING is
sysctl -q -w net.ipv4.conf.all.forwarding=1
iptables -N BLOCK
iptables -A BLOCK -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A BLOCK -m state --state NEW,ESTABLISHED -i eth0 -j ACCEPT
iptables -A BLOCK -m state --state NEW,ESTABLISHED -i lo -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.0/16 -j MASQUERADE
iptables -t nat -A POSTROUTING -o wan0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o wan1 -j MASQUERADE
Behind this gateway I'm running several web-servers. On one machine I'm running a HTTP Server on Port 8000 instead of 80. Usually when I'm using wan0 as the incoming interface I use the following rules:
lan_host1="192.168.0.200"
iptables -A FORWARD -i wan0 -p TCP -d $lan_host1--dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i wan0 -p TCP --dport 8000 -j DNAT --to-destination "$lan_host1":80
iptables -A FORWARD -i wan0 -p UDP -d $lan_host1--dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i wan0 -p UDP --dport 8000 -j DNAT --to-destination "$lan_host1":80
That works fine.
Now I would like wan1 to be used, as wan0 is tied to an IP/domain I usually use for something else.
I thought a simple change to wan1 would do it.
lan_host1="192.168.0.200"
iptables -A FORWARD -i wan1 -p TCP -d $lan_host1--dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i wan1 -p TCP --dport 8000 -j DNAT --to-destination "$lan_host1":80
iptables -A FORWARD -i wan1 -p UDP -d $lan_host1--dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i wan1 -p UDP --dport 8000 -j DNAT --to-destination "$lan_host1":80
But that doesn't work. I guess the issue is that wan0 is the default GW. So I guess packages received by wan1 are forwarded to lan_host1, but when being send back to the gateway they are send through wan0 instead of wan1 or at least using the ip from wan0.
Any suggestions how I could manage this?
Thanks in advance,
Rob
|
As the answer is tied to the configuration, I make some assumptions. You'll have to adapt the answer to fit the actual configuration.
wan1's LAN and gateway for wan1 arbitrarily chosen as 84.114.7.0/24 and 84.114.7.254.
no consideration of firewall rules made, but all this shouldn't interact with them.
On Linux ip link, ip address and ip route should always be used instead of deprecated ifconfig and route. route probably can't handle additional routing tables anyway.
Just as a reminder, iptables or actually netfilter, doesn't route, but it can by its actions alter routing decisions made by the IP routing stack. This schematic shows where routing decisions can happen. For routed (rather than locally originated) traffic that's only in one place and alterations must happen before: raw/PREROUTING, mangle/PREROUTING or nat/PREROUTING, with raw often impractical, and nat only for limited cases, mostly leaving mangle.
A basic multi-homed system, to use multiple paths to internet, usually requires policy routing, where the route can change not only with the destination as usual, but also with the source or with other selectors (as will be done here) used in policy rules. On Linux additional rules made with ip rule can select a different routing table to select for example a different default route (there will still be only one default route, but one per routing table).
So here the principle, while still keeping active Strict Reverse Path Forwarding (rp_filter), is to accept packets coming from wan1 and route them as usual toward eth0 using an alternate table (which will allow to pass rp_filter). This additional routing table should duplicate the main routing table, but using only routes needed for the alternate path (wan1) and thus not including the usual routes with the "normal" path (wan0). If other routes (such as VPNs etc.) have to be involved in flows going through wan1, chances are that their route too have to be added, or other additional rules and tables have to be created to cope with that.
Since Linux discontinued the use of a routing cache in kernel 3.6, nothing in the routing stack would tell to send back reply packets from host1 to the client through wan1 and they would end up going out using the main default route through wan0, NATed with the wrong IP for this interface (netfilter is route-agnostic and had already chosen the NAT to be done when receiving the first packet of the connection) and probably dropped by the next router of the ISP also doing Strict Reverse Path Filtering. There's a netfilter feature allowing to copy a packet's mark in the conntrack's mark and put it back in the packet: this will act as route memory for the connection. So iptables and netfilter's conntrack will be used for two related features: to mark the packet in order to alter the routing decision, and to restore this mark on the reply packets identified as part of the same connection.
All this translates to these commands:
routing part
Use for marked packets (arbitrary mark value 101) an extra routing table (unrelated arbitrary value also 101) :
ip rule add fwmark 101 lookup 101
Populate the table with entries similar the main routing table, minus wan0 entries:
ip route add table 101 192.168.0.0/16 dev eth0
ip route add table 101 84.114.7.0/24 dev wan1
ip route add table 101 default via 84.114.7.254 dev wan1
iptables/netfilter part
There are various optimizations possible in the following commands, It can probably be improved.
Restore a potential previous mark already saved, so reply packets will get the same mark as original packets:
iptables -t mangle -A PREROUTING -j CONNMARK --restore-mark
Mark packets arriving from wan1 to alter routing decision above:
iptables -t mangle -A PREROUTING -i wan1 -j MARK --set-mark 101
If there's a mark, save it in conntrack (could have been done in the nat table to do it only once per connection flow rather than for every packet):
iptables -t mangle -A PREROUTING -m mark ! --mark 0 -j CONNMARK --save-mark
Actually this will still fail a Strict Reverse Path Forwarding check, since this undocumented feature was added in 2010. It must be used here:
sysctl -w net.ipv4.conf.wan1.src_valid_mark=1
| iptables: MultiWAN and portforwarding & port redirection |
1,614,612,997,000 |
I recently started using iptables and i found that when running the wine command winecfg it freezes until i disable the iptables service. I also saw that applications like tshark freeze when ran. How can i fix this? Am i missing something?
Here are my current rules:
[Screenshot][1]:https://i.postimg.cc/xT1BwHY8/Screenshot-20190707-005954.png
UPDATE
So it seems wine needs access to the loopback address of 127.0.0.1 but since i have the output chain policy set to accept, how is it still hanging?
|
Solved it by adding the following rule to my iptables:
-A INPUT -p all -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
| Iptables hangs winecfg |
1,614,612,997,000 |
On my CentOS I have firewalld running and my eth0 is in default zone. I use dockers for my services to communicate and in dockers I have enabled encryption. Docker creates an overlay network and uses IPSEC. But firewalld drops IPSEC connection. I found a link which has about 5-6 commands for IPSEC to work and if I play those commands, things work fine.
These are listed on this link https://www.centos.org/forums/viewtopic.php?t=56130
I am not clear how the default zone is where my nic eth0 is and I have to modify dmz zone. What is the use of masquerade and port 4500?
firewall-cmd --zone=dmz --permanent --add-rich-rule='rule protocol value="esp" accept'
firewall-cmd --zone=dmz --permanent --add-rich-rule='rule protocol value="ah" accept'
firewall-cmd --zone=dmz --permanent --add-port=500/udp
firewall-cmd --zone=dmz --permanent --add-port=4500/udp
firewall-cmd --permanent --add-service="ipsec"
firewall-cmd --zone=dmz --permanent --add-masquerade
|
The masquerade rule tells the system to enable nat on outgoing connections, which is typical of networks using private internal addressing. It's a routing rule not technically related to ipsec specifically.
The port 4500 is used for ipsec nat traversal when one or both sides are behind other routers and don't have their own routable ip addresses.
Each nic belongs to a zone, zones are preconfigured with rules. internal, dmz and public are quite different from each other.
| enabling ipsec, ah and esp on CentOS with firewalld in place |
1,614,612,997,000 |
My workplace has several security policies that run counter to how I would usually set up my laptop. In particular, when connected to the network at work, we are forbidden from having an ssh daemon accepting connections. This generally leads to me getting in trouble at work (when I forget to shut down the sshd) or being unable to access my laptop remotely when it's not at work (when I forget to bring it back up), so I would like to automate this process.
Is there a way to automatically change the firewall rules or stop/start the sshd service depending on the SSID of the wifi network I am connected to? I am running CentOS6 if it makes a difference.
|
If you are using the standard dhclient configuration of CentOS 6 then after DHCP has completed it will run a series of "post" scripts.
Of use, here, is the /etc/dhcp/dhclient.d directory. These scripts will be run after the IP address has been obtained.
It would be pretty simple to add a script in here that would look at your wireless setup (iwconfig) and decide whether to stop or start sshd or whether to permit/deny port 22, or anything else you would like.
See here for some information on how the scripts need to be set up.
| Changing network settings depending on SSID |
1,614,612,997,000 |
I have a Fedora 24 server, serving an Angular2 project. Angular2 automatically opens ports 3000 and 3001 once the service is started. However, although running nmap localhost shows the ports are open, when I run an nmap from a remote computer, these ports are showing as closed.
Is there an iptables setting I can use to open these ports publicly, perhaps? Or anything similar?
I tried running:
iptables -A OUTPUT -p tcp -m tcp --dport 3000 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --dport 3001 -j ACCEPT
But this has not helped and the ports remain closed when scanned from outside, and I cannot view the served content (internal requests function fine).
Output of netstat --an | egrep "3000|3001":
tcp6 0 0 :::3000 :::* LISTEN
tcp6 0 0 :::3001 :::* LISTEN`
A curl to the server's 'external' IP address works fine internally but won't work when run from other machines.
|
In the end the solution was to run the following command:
firewall-cmd --zone=FedoraServer --add-port=3000/tcp
Seems that on Fedora 24, or the Fedora 24 as set up on linodes perhaps, iptables doesn't have a TCP entry.
| Fedora 24: ports show as open when scanned from server, but closed when nmapped from outside |
1,614,612,997,000 |
I just setup postfix but I just realized my ISP outgoing blocks port 25 (SMTP). How do I send email outside? I can see my mail queue is filling up. Any suggestion?
|
If your ISP is blocking outbound port 25, you've probably made a bad choice in the location of your mailserver. Because port 25 is blocked, I am assuming you have a machine inside your home/office, vs using a server.
I would highly recommend that you take what you've learned from setting up postfix and install it on a cheap VPS. It is not a good idea to have an intermittent mailserver, or one that jumps IPs.
Otherwise, your option is to get a cheap VPS and create a tunnel, but in doing this you'll most likely have to add the tunnel's ip to a TXT spf record, which starts complicating things.
| outgoing SMTP 25 port blocked by ISP? |
1,614,612,997,000 |
I need to block one incoming port with pf. I'm new to pf, and I can't figure out what I'm doing wrong here.
Here is my entire rule file, made to block incoming port 22:
set block-policy drop
pass in all keep state
pass out all keep state
block in proto tcp to port 22
After I start pf with sudo /sbin/pfctl -e -f /path/to/my/rule/file, all my network traffic is blocked. I try to load a webpage, and it won't load until I do sudo /sbin/pfctl -d to disable pf.
If I remove the fourth line (block in proto tcp to port 22) from my rule list, nothing is blocked. So what did I do wrong on the fourth line that is causing it to block everything instead of just incoming TCP port 22? All the examples did this similarly.
If it matters, my OS is OS X 10.8.5.
|
block all
pass in on fxp0 proto tcp from any to any port 22 flags S/SA
pass out on fxp0 proto tcp from any to any port 22 flags S/SA
Please consider you have to change fxp0 to your ethernet according to your operating OS.
Reverse of above:
pass in on fxp0 proto tcp from any to any port < 22 flags S/SA
pass out on fxp0 proto tcp from any to any port < 22 flags S/SA
pass in on fxp0 proto tcp from any to any port > 22 flags S/SA
pass out on fxp0 proto tcp from any to any port > 22 flags S/SA
block in on fxp0 proto tcp from any to any port 22
block out on fxp0 proto tcp from any to any port 22
| pf blocks all in/out traffic instead of just the one port I wanted to block |
1,392,509,316,000 |
I was recently delving into thoughts of building a small home server to run random things off of (maybe a TF2 server). Thinking about this further I realized I would need to get a better firewall system for my current home network. I was wondering what would be a good Linux distro to run for a home network firewall?
There are a ton of distro's out there, and it is kinda overwhelming when you're new to it. I have looked at Zentyal (previously eBox), SmoothWall, M0n0wall and a couple others. I have little experience in setting up firewalls, but I am willing to do some research into it and give it a shot. I would just like a little help with the starting ground. If someone could provide some pro's/con's of available distro's or some insight on what might be best to set up in a home network it would be appreciated!
Thanks!
|
The distro called ipcop exists since 2007 and is designed exactly for your purpose.
http://distrowatch.com/table.php?distribution=ipcop
I think there are many reasons strongly in favor of ipcop that put it ahead of the bunch:
Designed for your purpose
Long history + high ranking in google search "linux firewall distro"
Latest release: 2012 February
As the other post mentions, pfsense can be interesting to, a big difference is that pfsense (like moonwall) is based on FreeBSD, not on Linux.
| Linux Home Firewall |
1,392,509,316,000 |
I'm a long time fan of Slackware and I've always had a machine serving as my main server/firewall with the latest version installed.
I have it now but I'm struggling to find information on how to setup UPnP on it.
Can anyone please provide some good links where I can investigate further?
|
I think you are looking for linux-igd.
This project is a deamon that emulates
Microsoft's Internet Connection
Service (ICS). It implements the UPnP
Internet Gateway Device specification
(IGD) and allows UPnP aware clients,
such as MSN Messenger to work properly
from behind a NAT firewall.
This works fine with iptables...
| How would I go about getting UPnP working on a Slackware server/firewall? |
1,392,509,316,000 |
I have HPC that I want people to use it remotely without giving them access to other computers in the private network. Other computers are operating on network. I am using port forwarding.
sudo firewall-cmd --zone=public --add-source=192.34.1.145 --runtime-to-permanent
Where 192.34.1.145 is the particular remote IP. What am I doing wrong? How do I WRITE script to allow only them to access specific servers from specific IP without being able to hack data on private network? I think that they will be able to see my other computers.
|
This doesn't exactly answer your question, however, one of the easiest ways to do this is by using two routers to put the computer you want to access from the Internet on a physically separated network from your other computers. A decent router will allow you to specify the source IP address and port forward to an internal IP.
Connect both routers to your main Internet router. Put the Internet accessible computer behind one router and the rest of your computers behind a different router. Then, the Internet accessible computer is on it's own network and cannot see your other computers behind the other router. Don't forget to open a port on the router to the Internet accessible computer and also on your main router to the Internet accessible router.
You might not want to use a cheap consumer router that can be easily hacked from the Internet accessible computer. Or, you could put something like dd-wrt firmware on the routers. Use a really long password on the routers to help prevent brute forcing the routers password.
If you wanted to get fancy, you could use something like a Raspberry Pi as your router(s). Then you can customize it to your liking.
EDIT:
You really need two routers connected to your main router. There is something called ARP Cache Poisoning that can allow a hijacked machine plugged into your main router to redirect all LAN traffic through the hijacked machine. This could allow the machine to hijack machines behind your other router. This is called a man-in-the-middle (MITM) attack.
| How to safely allow particular remote IP access to particular servers on private network? |
1,392,509,316,000 |
I have a server running Debian 8 Jessie that constantly loses it's internet access for seemingly no reason. The server has two wired connections, the internet access is on eth0 and the internal network is on eth1. The internal connection is working as normal.
The content of /etc/network/interfaces is:
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 132.248.25.125
netmask 255.255.255.0
network 132.248.25.0
broadcast 132.248.25.255
gateway 132.248.25.254
dns-nameservers 132.248.204.1 132.248.10.2
allow-hotplug eth1
iface eth1 inet static
address 192.169.1.249
netmask 255.255.255.0
network 192.169.1.0
broadcast 192.169.1.255
gateway 192.169.1.10
ifconfig:
eth0 Link encap:Ethernet HWaddr 00:30:48:fe:a7:3c
inet addr:132.248.25.125 Bcast:132.248.25.255 Mask:255.255.255.0
inet6 addr: fe80::230:48ff:fefe:a73c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4278205 errors:0 dropped:8744 overruns:0 frame:0
TX packets:7134 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:371528685 (354.3 MiB) TX bytes:832677 (813.1 KiB)
Memory:f0000000-f001ffff
eth1 Link encap:Ethernet HWaddr 00:30:48:fe:a7:3d
inet addr:192.169.1.249 Bcast:192.169.1.255 Mask:255.255.255.0
inet6 addr: fe80::230:48ff:fefe:a73d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1206214 errors:0 dropped:2667 overruns:0 frame:0
TX packets:3028234 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:75759114 (72.2 MiB) TX bytes:4139225848 (3.8 GiB)
Memory:f0060000-f007ffff
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:4644 errors:0 dropped:0 overruns:0 frame:0
TX packets:4644 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1006417 (982.8 KiB) TX bytes:1006417 (982.8 KiB)
And for route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.169.1.10 0.0.0.0 UG 0 0 0 eth1
132.248.25.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.169.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
I'm very new to Linux so I'm not exactly sure what I'm looking for. My guess is that the default gateway is acting up, or the firewall is causing problems.
Any advice/help would be appreciated.
The results of ip a:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:30:48:fe:a7:3c brd ff:ff:ff:ff:ff:ff
inet 132.248.25.125/24 brd 132.248.25.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::230:48ff:fefe:a73c/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:30:48:fe:a7:3d brd ff:ff:ff:ff:ff:ff
inet6 fe80::230:48ff:fefe:a73d/64 scope link
valid_lft forever preferred_lft forever
And for ip r:
132.248.25.0/24 dev eth0 proto kernel scope link src 132.248.25.125
|
Comment out one gateway. The one without Internet connection:
#gateway 192.169.1.10
Standard configuration can have only one and your route shows it is the internal gateway used right now.
If there are other networks behind this gateway add this:
post-up /sbin/ip route add 192.169.X.0/24 via 192.169.1.10
post-down /sbin/ip route del 192.169.X.0/24 via 192.169.1.10
for every network behind internal gateway.
| Debian Jessie server has no internet access |
1,392,509,316,000 |
I'm working on a live stream transcoder application using nginx + ffmpeg.
Everything works fine when I use avconv to transcode, but if I use ffmpeg, I get this error:
[tcp @ 0xb4e9da0] Failed to resolve hostname fso.dca.XXXX.edgecastcdn.net: System error
Any hints? Seems like an application specific firewall.
|
The problem is with the static build, as @slm mentioned. I've compiled ffmpeg from source and things work fine now.
| Application specific DNS problem? |
1,392,509,316,000 |
I have been trying to set up iptables on my archlinux server, however when I run iptables -nvL I receive the error
iptables v1.4.20: can't initialize iptables table 'filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
Having tried to load the modules and failing I checked to see if they were installed using modinfo and they could not be found. I was trying to run these modules x_tables, ip_tables, ip_filter, iptable_filter, xt_tcpudp, nf_conntrack, xt_state, nf_conntrack_ipv4 Does anybody know how to solve this problem?
EDIT:
Having done some more research on the problem I think I may need to install the necessary modules manually. Is this something which is possible over ssh? I am not sure how to go about rebuilding the kernel.
|
As I run a custom kernel, I do not know if the module needed for the filter table is included in the stock arch kernel. But perhaps you do not even need exactly this table. On my system, I normally just use the nat table.
Pass the parameter -t to all iptables invocations to select a given table, for example trying iptables -nvLt nat
| Archlinux not configured with iptables |
1,371,236,423,000 |
I would like to restrict access to the SSH port of a new CentOS 6.2 server to select IP addresses but the Firewall GUI utility seems to be an all-or-nothing scenario. Either the port is firewalled or it is opened.
If I make changes using the IPTABLES commands and save them out, and then later someone uses the Firewall GUI to make other modifications such as opening up access to FTP or the like, will that remove the changes I made using the IPTABLES commands or manual edits to the tables?
|
Yes, the changes in the GUI will overlay /etc/sysconfig/iptables. I found this out the hard way recently.
| Will the Firewall GUI in CentOS overwrite changes implemented by IPTABLES manual edits? |
1,371,236,423,000 |
It is possible using iptables (on Debian) to block all inbound connections for all the ports with a port number over (as an example) 16000.
Like this (using 16000 as reference):
The port 15999 is open for input, instead from port 16000 to 65535 inbound connections are dropped.
|
If the ports are contiguous, like yours are, then use the
--destination-port,--dport [!] port[:port]
syntax to set up the range:
... --destination-port 16000:65535 ...
| iptables: block all inbound traffic over a certain port number |
1,371,236,423,000 |
This question is a follow-up to my previous question.
Logic for me to says that an in-kernel firewall sits between the network access layer and the Internet layer, because it needs to have access to the IP-packet header to read the source and destination IP address in order to do filtering before determining if the packet is destined for the host, or it the packet should forwarded to the next hop if it is destined elsewhere.
Somehow, it also seems logical to say that firewall is part of Internet layer, because that is where routing table is and a firewall is in some respects similar to routing table rules.
|
A firewall does not exist in a single place in the kernel network stack. In Linux, for instance, the underlying infrastructure to support firewall functionality is provided by the netfilter packet filter framework.
The netfilter framework in itself is nothing more than a set of hooks at various points in the kernel protocol stack.
Netfilter provides five hooks:
NF_IP_PRE_ROUTING
Packets which pass initial sanity checks are passed to the NF_IP_PRE_ROUTING hook. This occurs before any routing decisions have been made.
NF_IP_LOCAL_IN
Packets which destined to the host itself are passed to the NF_IP_LOCAL_IN hook.
NF_IP_FORWARD
Packets destined to another interface are passed to the NF_IP_FORWARD hook.
NF_IP_LOCAL_OUT
Locally created packets are passed to NF_IP_LOCAL_OUT after routing decisions have been made, although the routing can be altered as a result of the hook.
NF_IP_POST_ROUTING
The NF_IP_POST_ROUTING hook is the final hook packets can be passed to before being transmitted on the wire.
A firewall consists of a kernel module, which registers a callback function for each of the hooks provided by the the netfilter framework; and userspace tools for configuring the firewall. Each time a packet is passed to a hook, the corresponding callback function is invoked. The callback function is free to manipulate the packet that triggered the callback. The callback function also determines if the packet is processed further; dropped; handled by the callback itself; queued, typically for userspace handling; or if the same hook should be invoked again for the packet.
Netfilter is usually associated with the iptables packet filter. As Gnouc already pointed out in your previous question, iptables has a kernel module, ip_tables, which interfaces with netfilter, and a userspace program, iptables, for configuring the in-kernel packet filter. In fact, the iptables packet filter provides several tools, each associated with a different kind of packet processing:
The iptables userspace tool and ip_tables kernel module concern themselves with IPv4 packet filtering.
The ip6tables userspace tool and ip6_tables kernel module concern themselves with IPv6 packet filtering.
The arptables userspace tool and arp_tables kernel module concern themselves with ARP packet filtering.
In addition to the iptables packet filters, the ebtables userspace tool and eb_tables kernel module concern themselves with link layer Ethernet frame filtering. Collectively, these tools are sometimes referred to as xtables, because of the similar table-based architecture.
This architecture provides a packet selection abstraction based on tables packets traverse along. Each table contains packet filtering rules organized in chains. The five predefined chains, PREROUTING, INPUT, FORWARD, OUTPUT and POSTROUTING correspond to the five in-kernel hooks provided by netfilter. The table a rule belongs to determines the relative ordering of rules when they are applied at a particular netfilter hook:
The raw table filters packets before any of the other table.
The mangle table is used for altering packets.
The nat table is used for Network Address Translation (e.g. port forwarding).
The filter table is used for packet filtering, it should never alter packets.
The security table is used for Mandatory Access Control (MAC) networking rules implemented by Linux Security Modules (LSMs), such as SELinux.
The following diagram by Jan Engelhardt shows how the tables and chains correspond to the different layers of the OSI-model:
Earlier this year, a new packet filter framework called nftables was merged in the mainline Linux kernel version 3.13. The nftables framework is intended to replace the existing xtables tools. It is also based on the netfilter infrastructure.
Other kernel-based firewalls in Unix-like operating systems include IPFilter (multi-platform), PF (OpenBSD, ported to various other BSD variants and Mac OS X), NPF (NetBSD), ipfirewall (FreeBSD, ported to various operating systems).
| Does an in-kernel firewall sit between the network access layer and Internet layer? |
1,371,236,423,000 |
I'm trying to atomically replace nftables rules. Nftables's official wiki states that -f is the recommended way to achive this. However, when I run nft -f /path/to/new/rules on Debian Buster, the new rules get added to the current rules instead of replacing them, and I end up with a system enforcing both rule-sets simultaneously.
The same thing occurs when I try to reload configuration via systemd's nftables.service.
How can I get nft to discard the current rule-set while also adding a new rule-set in a single atomic operation?
|
The operation done with nft -f /path/to/new/rules is atomic: that means it's either done completely or not done at all (ie: reverted), and will affect all at once the next packet hitting the rules only once committed. It won't end (because of an error) only half-done. So if you don't delete the previous ruleset before, it behaves as expected: it atomically adds rules once more, as described in the notes of Atomic rule replacement in the wiki:
Duplicate Rules: If you prepend the flush table filter line at the
very beginning of the filter-table file, you achieve atomic rule-set
replacement equivalent to what iptables-restore provides. The kernel
handles the rule commands in the file in one single transaction, so
basically the flushing and the load of the new rules happens in one
single shot. If you choose not to flush your tables then you will see
duplicate rules for each time you reloaded the config.
For this you must, in the same transaction delete older rules before adding again your ruleset. The easiest (but affecting all of nftables, including iptables-nft if also used) is simply, similarly to what is described above, to prepend your ruleset /path/to/new/rules with:
flush ruleset
If you're loading different tables at different times to keep logical features separated (in nftables, a table can include any type of base chain (for the given family), it's not the direct equivalent of a table in iptables which has a fixed set of possible chain) it becomes a bit more complex because flush ruleset in one rule file would delete other tables (including iptables-nft rules if used along nftables). Then this should be done at the table level with for example (but read further before doing):
delete table inet foo
followed by the redefinition of it (table inet foo { ...). As-is, this creates an other chicken-and-egg problem: the first time this file would be read, eg at boot, the delete operation would fail, and thus everything would atomically fail as a whole because the table didn't exist. As declaring an already declared table's name is considered a no-op and thus won't fail, in the end this can be done:
table inet foo
delete table inet foo
table inet foo {
[...]
note 1: For this to work properly in all cases kernel >= 3.18 is required, else better stick to flush ruleset.
note 2: the wiki's note above suggests using for this case flush table inet foo but this should probably be avoided, because if sets are present this won't delete element in sets, leading again to adding instead of replacing elements if the elements are added by the ruleset and were changed there. It won't either allow to redefine the type/hook of a base chain. Using table inet foo + delete table inet foo doesn't have these drawbacks. Of course if one needs to keep elements in sets when reloading rules, one might ponder using flush table inet foo and adapt to the limitations of this method.
In all cases you should be careful when using nft list {ruleset, table inet foo, ...} > /path/to/new/rules to dump the current rules to a rule file: it won't include any flush or delete command, and you'll have to add them back manually. You can probably use include to overcome this by keeping your "plumber" statements outside of the actual rules.
| How do I replace nftables rules atomically? |
1,371,236,423,000 |
I'm a bit lost here, so I'm asking for your help. =D
I have three servers:
1# - LANs A and B
2# - LANs B and C
3# - LANs C and D
How can I make server 1# access through LAN B an ip that is in LAN D of the 3# server using the 2# server?
NOTE: We can use the firewall-cmd (iptables) or any other feature that is available on a CentOS 7.
To illustrate
LAN B - 192.168.56.0/24
LAN C - 10.8.0.0/24
LAN D - 10.0.4.0/24
That is, a ping (ping 10.0.4.4) runs on the server 1# 'traversing' path B -> C -> D.
NOTE: I've done many and many tests and I really do not know how to solve this... =[
EDIT #1
To make things easier, I decided to enrich this thread with real information.
Server #1
LAN A -> Ignored
LAN B -> enp0s17 (192.168.56.0/24)
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:12:26:e2:6c brd ff:ff:ff:ff:ff:ff
inet 192.168.56.122/24 brd 192.168.56.255 scope global noprefixroute enp0s17
valid_lft forever preferred_lft forever
inet6 fe80::a00:12ff:fe26:e26c/64 scope link
valid_lft forever preferred_lft forever
Server #2
LAN B -> enp0s17 (192.168.56.0/24)
LAN C -> tun0 (10.8.0.0/24)
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:2c:d1:58 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.10/24 brd 10.0.2.255 scope global noprefixroute dynamic enp0s8
valid_lft 888sec preferred_lft 888sec
inet6 fe80::2c5c:27aa:2636:8dc9/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:1c:a6:b9:59 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.120/24 brd 192.168.56.255 scope global noprefixroute enp0s17
valid_lft forever preferred_lft forever
inet6 fe80::a00:1cff:fea6:b959/64 scope link
valid_lft forever preferred_lft forever
5: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 100
link/none
inet 10.8.0.1/24 brd 10.8.0.255 scope global tun0
valid_lft forever preferred_lft forever
inet6 fe80::6a67:7379:b64:967c/64 scope link flags 800
valid_lft forever preferred_lft forever
Server #3
LAN C -> tun0 (10.8.0.0/24)
LAN D -> enp0s8 (10.0.4.0/24)
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:71:77:07 brd ff:ff:ff:ff:ff:ff
inet 10.0.4.4/24 brd 10.0.4.255 scope global noprefixroute dynamic enp0s8
valid_lft 1115sec preferred_lft 1115sec
inet6 fe80::899f:8ca4:a7c6:25a7/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:ea:4e:40:ae brd ff:ff:ff:ff:ff:ff
inet 192.168.56.121/24 brd 192.168.56.255 scope global noprefixroute enp0s17
valid_lft forever preferred_lft forever
inet6 fe80::a00:eaff:fe4e:40ae/64 scope link
valid_lft forever preferred_lft forever
4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 100
link/none
inet 10.8.0.6/24 brd 10.8.0.255 scope global tun0
valid_lft forever preferred_lft forever
inet6 fe80::48c2:b3cd:5845:5d35/64 scope link flags 800
valid_lft forever preferred_lft forever
Based on the @slm suggestions we did the following:
Commands on Server #2
$ echo -n "net.ipv4.ip_forward=1" >> /etc/sysctl.d/ip_forward.conf
$ sysctl -w net.ipv4.ip_forward=1
$ firewall-cmd --permanent --direct --passthrough ipv4 -t nat \
-I POSTROUTING -o tun0 -j MASQUERADE -s 192.168.56.0/24
$ firewall-cmd --reload
Commands on Server #1
$ ping 10.0.4.4
PROBLEM -> There is no response for the ping 10.0.4.4 command.
IMPORTANT -> These are tests I'm doing on virtual machines.
|
That's a very basic networking thing: If you want to connect different LAN segments, you need a router. You don't need NAT, you don't need iptables, you just route, plain and simple.
For some reason people seem to think routing needs at least NAT or iptables, and the internet is full of advice to that end. It's really not necessary, and a pet peeve of mine.
All you need to do is
1) Enable forwarding on server #2. That has already been described (add a file in /etc/sysctl.d/, reboot and see if cat /proc/sys/net/ipv4/ip_forward shows 1, or enable it directly with echo 1 > /proc/sys/net/ipv4/ip_forward).
2) Set a route on all hosts which want to use the gateway. That's what most people forget. So on server #1, you need something like
ip route add 10.8.0.0/24 dev enp0s17 via 192.168.56.120
ip route add 10.0.4.0/24 dev enp0s17 via 192.168.56.120
and the same on all other hosts on LAN A and B which want to reach LAN C and D. On server #3 (and all other hosts it concerns), you need
ip route add 192.168.56.0/24 dev tun0 via 10.8.0.1
That tells each host that when it wants to reach the remote LAN, it should go via server #2, with the appropriate IP address of server #2 in the local LAN.
You can test that routing works with ip route get a.b.c.d on server #1 and server #3. Now test with ping. If something is still wrong, debug with tcpdump. If a firewall is in the way, disable it as necessary.
When all works, use some way to make the routes permanent, for example distribute them via DHCP, or add them to a suitable configuration file.
| Use the LANs of one server to access the LAN of another |
1,371,236,423,000 |
I would like to restrict visibility of my server from outside my country. I am connecting to my personal server always from one or two countries. Is there a way to block all the IPs coming from all the other countries?
I am running Debian with iptables.
I have found the following database of IPs associated to countries, however it's not very accurate. Any other idea?
ftp://ftp.arin.net/pub/stats/arin/delegated-arin-extended-latest (North America)
ftp://ftp.ripe.net/ripe/stats/delegated-ripencc-latest (Europe)
ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest (Africa)
ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-latest (Asia + Pacific)
ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest (South America)
|
You can use xtable addons geoip match feature. On debian install the xtable-addons-common package and then use use the geoip target e.g. to allow ssh from Netherlands NL:
iptables -A INPUT -p tcp --dport 22 -m geoip --src-cc NL -j ACCEPT
Make sure xt_geoip module is loaded and geoip database is downloaded. You can read xtable documentation for more information on this at http://xtables-addons.sourceforge.net/geoip.php
| Block countries based on IP in firewall |
1,371,236,423,000 |
I have a domain which I want to point to my server.
But I don't want to allow other people to use this domain to reach the server, only specific ports on the server (web server, so port 80).
So if someone want to reach the server on my domain on port x then don't let it, but if the port is y then let.
Is it possible somehow?
|
You can not, with one IP address. The server is not being addressed by name, only by address. It doesn't matter which hostname resolves to the address, the same connection will happen. The port also is not used in name resolution, so you cannot affect that in any way.
The only practical way would be to put the names to point to different IPs, all of which are used on that server. This will look like only certain ports are accepted, but of course the user can change the hostname or access the server via the other IP directly.
| Domain only for web server |
1,371,236,423,000 |
Now I perform this:
create blockipset hash:ip
add blockipset 192.168.1.5 -exist
add blockipset 192.168.3.115 -exist
Is it possible for iptables and ipset to block ip,port and ip?
for example, the list contains:
192.168.1.5
192.168.3.115
192.168.1.55,80
192.168.1.53,22
|
You can't put different types of elements in the same set with the ipset command. But you can use different sets, one for each type (full list available with ipset help):
hash:ip
hash:ip,port
For example:
ipset create blocklistip hash:ip
ipset create blocklistipport hash:ip,port
ipset add blocklistip 192.0.2.3
ipset add blocklistipport 192.0.2.2,80
ipset add blocklistipport 192.0.2.3,udp:53
Note like above that by default the protocol for the port is TCP unless explicitly stated otherwise (udp: for UDP, sctp: for SCTP, ...).
Now your script has to check what type of element it got, to know in what ipset it will add it. A simple example here would be to check for the , to know where to put it, while reading the list from the file blocklist.txt:
while read -r element; do
if echo $element|grep -q ,; then
ipset add blocklistipport $element
else
ipset add blocklistip $element
fi
done < blocklist.txt
And you can block everything in the list for example with:
iptables -A INPUT -m set --match-set blocklistip src -j DROP
iptables -A INPUT -m set --match-set blocklistipport src,dst -j DROP
Above src,dst means use the source IP address along the destination port address in the packet when looking for a match in the hash:ip,port set.
Also, ipset has a special set list:set consisting of a list of other sets. This won't change the way to populate separately the sets using the ipset command, but you can do this:
ipset create blocklist list:set
ipset add blocklist blocklistip
ipset add blocklist blocklistipport
and replace the two previous iptables rules with only the one below:
iptables -A INPUT -m set --match-set blocklist src,dst -j DROP
which goes toward your goal: this single iptables rule will work correctly with set elements with or without a port, as documented in ipset.
| iptables add ip,port and also IP |
1,371,236,423,000 |
I have a very strange behaviour of my UFW on Ubuntu 18.04.
I set up basic rules, everything is OK until I connect client to this server through VPN. On the client side ping works fine but nslookup / domain ping is being refused. Once I will turn off ufw, it is working well.
UFW configuration: VPN subnet is 10.99.0.0/24 (using OpenVPN):
ufw default deny incoming
ufw default allow outgoing
1194 ALLOW Anywhere
Anywhere ALLOW 10.99.0.0/24
6969 ALLOW 10.99.0.0/24
10.99.0.0/24 ALLOW Anywhere
And from the log (using 8.8.8.8 and 1.0.0.1 as DNS):
Dec 7 23:40:28 snm kernel: [15432.700282] [UFW BLOCK] IN=tun0 OUT=eth0 MAC= SRC=10.99.0.2 DST=1.0.0.1 LEN=71 TOS=0x00 PREC=0x00 TTL=127 ID=1189 PROTO=UDP SPT=64312 DPT=53 LEN=51
Dec 7 23:41:08 snm kernel: [15472.370487] [UFW BLOCK] IN=tun0 OUT=eth0 MAC= SRC=10.99.0.2 DST=1.0.0.1 LEN=71 TOS=0x00 PREC=0x00 TTL=127 ID=1192 PROTO=UDP SPT=50962 DPT=53 LEN=51
Dec 7 23:41:09 snm kernel: [15473.384535] [UFW BLOCK] IN=tun0 OUT=eth0 MAC= SRC=10.99.0.2 DST=8.8.8.8 LEN=71 TOS=0x00 PREC=0x00 TTL=127 ID=1193 PROTO=UDP SPT=50962 DPT=53 LEN=51
Do you have any advise how to debug this?
|
If all you are looking at is the domain ping failure, the server and or client firewall needs to be made to allow forwarding:
# Allow TUN interface connections to OpenVPN server
iptables -A INPUT -i tun+ -j ACCEPT
# Allow TUN interface connections to be forwarded through other interfaces
iptables -A FORWARD -i tun+ -j ACCEPT
More information: HERE
Also look into the client-to-client setting, this is required to gain access to other computers on the VPN, if not enabled you can't see the other computers connected.
Uncomment out the client-to-client directive if you would like connecting clients to be able to reach each other over the VPN. By default, clients will only be able to reach the server.
More information found: HERE
| UFW is blocking DNS requests through VPN [closed] |
1,371,236,423,000 |
Right now I'm trying to figure out how to set up some IPv6 rules on a server of mine. My requirements are to disallow input echo-requests to the loopback device and local IP addresses (in this case, link-local), as well as open up ports 22, 80, and 443. Everything works great for IPv4, but I'm having an issue with ip6tables following the chain order for INPUT it seems. Here's what I have now:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p icmpv6 -m icmpv6 --icmpv6-type echo-request -j ACCEPT
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
-A INPUT -j REJECT
-A FORWARD -j REJECT --reject-with icmp6-port-unreachable
-A OUTPUT -p icmpv6 --icmpv6-type echo-request -d ::1/128 -j REJECT --reject-with icmp6-port-unreachable
-A OUTPUT -p icmpv6 --icmpv6-type echo-request -d fe80::/64 -j REJECT --reject-with icmp6-port-unreachable
-A OUTPUT -j ACCEPT
COMMIT
Currently my culprit line is -A INPUT -j REJECT. My expectations are it will do an implicit deny of everything not listed above in the chain. This doesn't seem to be the case though, and seems to behave differently than plain old iptables with IPv4 rules. Can someone enlighten me on the solution here? This is an Ubuntu 14.04 server
|
Let's see what your rules are trying to do first, to see why they might not be working:
-A INPUT -i lo -j ACCEPT
All traffic arriving at the loopback interface will be processed, including ICMPv6 traffic.
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
Pretty normal.
-A INPUT -p icmpv6 -m icmpv6 --icmpv6-type echo-request -j ACCEPT
This rule, as written, will only allow ping requests (to any interface): any other ICMPv6 packets will be denied by the explicit REJECT at the end.
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
-A INPUT -j REJECT
-A FORWARD -j REJECT --reject-with icmp6-port-unreachable
Pretty normal.
-A OUTPUT -p icmpv6 --icmpv6-type echo-request -d ::1/128 -j REJECT --reject-with icmp6-port-unreachable
-A OUTPUT -p icmpv6 --icmpv6-type echo-request -d fe80::/64 -j REJECT --reject-with icmp6-port-unreachable
These rules will only prevent your host from sending pings to the localhost and link-local network addresses (also, the link-local address range is a /10.)
-A OUTPUT -j ACCEPT
Pretty normal.
However, you said: "My requirements are to disallow input echo-requests to the loopback device and local IP addresses (in this case, link-local) [...]". Your rules as written are almost the opposite of what you wanted for this requirement. As well, it's usually better to put input filters on the input side, as that's where most people are going to look for stuff like this, and it will be effective for all traffic, not just traffic that your computer is sending.
I would recommend writing your rule chains as follows:
-A INPUT -i lo -p icmpv6 -m icmpv6 --icmpv6-type echo-request -j REJECT --reject-with icmp6-port-unreachable
-A INPUT -d fe80::/10 -p icmpv6 -m icmpv6 --icmpv6-type echo-request -j REJECT --reject-with icmp6-port-unreachable
-A INPUT -p icmpv6 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
-A INPUT -j REJECT
-A FORWARD -j REJECT --reject-with icmp6-port-unreachable
Some observations about the rewritten rules:
I prefer to put REJECT rules in front of ACCEPT rules, and narrower filters in front of wider filters so that I don't accidentally allow something through because it was allowed by a wider filter. It isn't a hard-and-fast rule, but it helps me to visualize what's going on a bit easier.
The OUTPUT chain is not needed anymore because the rules are handled in the INPUT chain instead.
Although you have it as a requirement, I'm not certain why you want to disallow pings to the loopback interface as only the local computer can send to that interface. This is only an observation, though: if you have a particular need to do this, that's fine.
| Help with IPv6 rules and ip6tables |
1,371,236,423,000 |
I'm trying to configure Iptables of a server in order to permit SSH incoming connections only from a certain network.
by the way this is the rule chain :
# Drop anything we aren't explicitly allowing. All outbound traffic is okay
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type echo-reply -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type time-exceeded -j ACCEPT
# Accept Pings
-A RH-Firewall-1-INPUT -p icmp --icmp-type echo-request -j ACCEPT
# Log anything on eth0 claiming it's from a local or non-routable network
# If you're using one of these local networks, remove it from the list below
-A INPUT -i eth0 -s 10.0.0.0/8 -j LOG --log-prefix "IP DROP SPOOF A: "
-A INPUT -i eth0 -s 172.16.0.0/12 -j LOG --log-prefix "IP DROP SPOOF B: "
-A INPUT -i eth0 -s 192.168.0.0/16 -j LOG --log-prefix "IP DROP SPOOF C: "
-A INPUT -i eth0 -s 224.0.0.0/4 -j LOG --log-prefix "IP DROP MULTICAST D: "
-A INPUT -i eth0 -s 240.0.0.0/5 -j LOG --log-prefix "IP DROP SPOOF E: "
-A INPUT -i eth0 -d 127.0.0.0/8 -j LOG --log-prefix "IP DROP LOOPBACK: "
# Accept any established connections
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Accept ssh traffic. Restrict this to known ips if possible.
-A INPUT -p tcp -s 88.253.5.38 --dport 22 -j ACCEPT
# Opening port 80 and port 443 in order to allow http and https requests
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
#Log and drop everything else
-A RH-Firewall-1-INPUT -j LOG
-A RH-Firewall-1-INPUT -j DROP
COMMIT
Saving those rules using following commands seems to apply them correctly:
/etc/init.d/iptables restart && service iptables save
# iptables -nvL
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
25332 17M RH-Firewall-1-INPUT all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 LOG all -- eth0 * 10.0.0.0/8 0.0.0.0/0 LOG flags 0 level 4 prefix `IP DROP SPOOF A: '
0 0 LOG all -- eth0 * 172.16.0.0/12 0.0.0.0/0 LOG flags 0 level 4 prefix `IP DROP SPOOF B: '
0 0 LOG all -- eth0 * 192.168.0.0/16 0.0.0.0/0 LOG flags 0 level 4 prefix `IP DROP SPOOF C: '
0 0 LOG all -- eth0 * 224.0.0.0/4 0.0.0.0/0 LOG flags 0 level 4 prefix `IP DROP MULTICAST D: '
0 0 LOG all -- eth0 * 240.0.0.0/5 0.0.0.0/0 LOG flags 0 level 4 prefix `IP DROP SPOOF E: '
0 0 LOG all -- eth0 * 0.0.0.0/0 127.0.0.0/8 LOG flags 0 level 4 prefix `IP DROP LOOPBACK: '
0 0 ACCEPT tcp -- * * 88.253.5.38 0.0.0.0/0 tcp dpt:22
Chain FORWARD (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 RH-Firewall-1-INPUT all -- * * 0.0.0.0/0 0.0.0.0/0
Chain OUTPUT (policy ACCEPT 25163 packets, 17M bytes)
pkts bytes target prot opt in out source destination
Chain RH-Firewall-1-INPUT (2 references)
pkts bytes target prot opt in out source destination
24175 17M ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmp type 0
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmp type 3
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmp type 11
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmp type 8
1052 121K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
94 6016 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
11 440 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4
11 440 DROP all -- * * 0.0.0.0/0 0.0.0.0/0
The critical part where i'm having difficulties is :
-A INPUT -p tcp -s 88.253.5.38 --dport 22 -j ACCEPT
What i'm trying to achieve is to allow connection only from this LAN where i'm at, for this I have checked from here the external ip of my router(it is statical ip) , and it returned lets say 88.253.5.38
My main doubt is, am I doing the right thing by using the external IP of my router? or should I use the internal ip of my machine, or the range of internal ip addresses?
Or maybee the whole chain have some conflict that don't permit the configuration i'm trying to do?
Thanks for any push, im really stuck
|
Am I doing the right thing by using the external IP of my router? or should I use the internal ip of my machine, or the range of internal ip addresses?
TL;DR: if your server is "across the Internet" from your own machine, you use the router's address in your iptables rules.
Longer answer:
The firewall rules work from the perspective of the device being firewalled. Ideally every device in the world would have its own IP address. But they don't, and we have this ugly hackery called NAT. In the simplistic case this is a device or piece of software that takes a range of IP addresses such as 192.168.1.* and maps them to a single IP address. The 192.168.* addresses are guaranteed to be unroutable, so they can never be found on the real Internet. Each person's network is hidden behind a NAT device, so that each network is presented as a single unique IP address. Therefore many people can use the same range of addresses 192.168.* on their internal networks as no-one else gets to see them directly.
So, back to the question.
If your server is "outside" your NATed network then it will only see the single public address. So that is what must go in the iptables rules.
On the other hand, if your server is connected to your own network without a NAT device between them, then the actual internal addresses must be used.
This is a highly simplified version of the ugly reality of IPv4 Internet addressing, but it should get you started.
Now to answer your specific issue, which is why your iptables rules don't work as expected. Start with the INPUT chain and follow it sequentially. The very first line calls the chain RH-Firewall-1-INPUT. As you follow that through you'll see a pair of rules that ACCEPT traffic on ports 80 and 443. And then there's a DROP rule for everything else. At the end of that chain we return to INPUT and finally reach your ACCEPT for port 22. But all traffic is already being dropped by this point so the rule is irrelevant.
A solution here is to move your ACCEPT rule for port 22 into the RH-Firewall-1-INPUT chain, immediately after the rules for ports 80 and 443, but before the catch-all DROP.
The proper solution, I suspect, is to learn to use firewalld, but I don't know if that was available in CentOS 6.x or whether it first arrived only in CentOS 7.
| iptables configuration - ssh connection only from a remote network |
1,371,236,423,000 |
I have firewalld installed in a remote CentOS server. When I log into the server over the internet as root, I type the following command to access the firewalld logs:
journalctl --output=json-pretty UNIT=firewalld.service
The result is a few records indicating when the service was turned on, etc.
How do I get the list of attempts that remote users tried to connect with the server? Including ip addresses, whether or not they where blocked by firewalld, what they were requesting, what ports, etc.
|
If there is no logging specified in the firewall rule that rejects the connection attempts, then nothing will appear in the log.
I suggest you read the RedHat firewalld reference which discusses adding logging requirements to firewall rules. Unfortunately, it's fairly complex and there are no shortcuts that I know of.
| viewing firewalld logs via remote login to CentOS 7 server |
1,371,236,423,000 |
I was seeing this question which was concerned with blocking access to the users who do not belong to a particular region. I am sure that blocking is possible but I see there is a workaround to this.
I login to the region's proxy from here.
I give this URL as the site to visit.
Now, I am in the region's proxy and I am able to login to the server
as well.
Is there a way to reject such circumvented attempts in the iptables? I see this as a pretty dangerous security concern.
|
This question looks very confused, but I think the confusion is part of the question, so I'll try to provide enough background to clarify things.
HTTP and SSH are different protocols. HTTP is spoken by HTTP clients (called web browsers) and HTTP servers (called web servers). SSH is spoken by SSH clients and SSH servers. The HTTP protocol has a notion of proxy, where a network node receives an HTTP requests from a client and forwards it to a server, and forwards the response back from the server to the client. SSH doesn't have proxies in the technical sense; however a machine that allows people who aren't using it physically to use an SSH client on it is acting as a proxy in the general English sense of the term.
http://www.freeproxy.ca/ lists HTTP proxies. They aren't useful to make SSH connections.
http://www.serfish.com/console/ is a machine that runs an SSH client which is driven from a publicly accessible web interface. If you use a web browser to connect to serfish, and run the SSH client there, then as far as the SSH server is concerned, your connection comes from serfish, full stop. There is no way for the SSH server to know that the SSH client is being driven by someone who isn't physically located in the datacenter where serfish is hosted. Note that it doesn't matter whether you're accessing serfish directly over HTTP or via an HTTP proxy; the SSH server has no way to know anything about that.
In general, a server can only know about the last hop used to connect to it. Is this a security concern? Yes, but hardly a dangerous one. Filtering connections by geographical origin cannot be done reliable; any moderately competent system administrator knows that. Geographical origin can give a clue as to whether a connection is suspicious, but it can't be the only factor. There are machines infected by malware and used as relays all over the world.
The security of SSH doesn't rely on geographical origin of connections. Filtering by geographical origin is done for only two purposes:
For content distribution, to restrict what the non-technical 95% of the audience can do (setting proxies requires digging further than a majority of people are willing to do) and make things a bit more inconvenient for the technical 5% (proxies need to be paid or searched for, and reduce performance).
As a hint that a connection to an account comes from an unusual location — but that's usually done at a finer-grained level than a country, which is too broad to provide a very useful hint. Some systems use this to decide whether to require a second authentication factor.
The flip side of not being able to track the ultimate origin of an SSH (or any) connection is that some amount of privacy is possible.
| Reject ssh connections made from proxies |
1,371,236,423,000 |
when I add following rule to iptables, everything works as expected. The offending IP is added to BLACKLIST and dropped.
iptables -A INPUT -m recent --rsource --name BLACKLIST --update -j DROP
when I list my iptables rules with iptables-save, I see that automatically a netmask 255.255.255.255 is used for matching:
-A INPUT -i eth0 -m recent --update --name BLACKLIST --mask 255.255.255.255 --rsource -j DROP
but when I explicitly specify other mask in my rules, while I see the changed mask in iptables-save, it does not have the desired effect of blocking whole subnet:
-A INPUT -i eth0 -m recent --update --name BLACKLIST --mask 255.255.0.0 --rsource -j DROP
but I see individual IPs getting through:
128.90.177.13
128.90.177.136
128.90.177.35
and individually being added to my BLACKLIST.
if mask worked, then first IP 128.90.177.13 would be added to BLACKLIST, and the other IPs from the same subnet would be blocked. But this is not what happens. They get through my rule.
Why is iptables recent --mask not working ?
I am using iptables module in kernel 4.14.274
so, to sum up:
I want to add offending IP to my BLACKLIST, and block whole subnet of this IP, based on netmask.
|
It's hard to figure out what's going on in your environment without seeing a complete netfilter configuration. However, we can try putting together a simple one here and see how it behaves.
Let's start with an empty netfilter ruleset and add the following rules:
iptables -N bl_add
iptables -A bl_add -j LOG --log-prefix "BL_ADD "
iptables -A bl_add -j DROP
iptables -N bl_update
iptables -A bl_update -j LOG --log-prefix "BL_UPDATE "
iptables -A bl_update -j DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m recent --name BLACKLIST --update --mask 255.255.0.0 --seconds 20 -j bl_update
iptables -A INPUT -p tcp --dport 80 -m recent --name BLACKLIST -i eth0 --set -j bl_add
Here we have a couple of log/drop chains that we can use to figure out exactly where our packets are going. The -i lo rule isn't critical; that's just to prevent me from shooting myself in the foot.
In the man page, we see the following documentation for --update:
[!] --rcheck
Check if the source address of the packet is currently in
the list.
[!] --update
Like --rcheck, except it will update the "last seen"
timestamp if it matches.
So the --update options means "check (i.e. match) if the address is in the list, and if it is, update the 'last seen' timestamp". We can see the behavior in action in this example.
If I attempt to connect to port 80 on this host from 192.168.122.1, we see in the logs (journalctl -kfl):
[ 4152.729894] BL_ADD IN=eth0 OUT=
MAC=52:54:00:01:89:30:52:54:00:5d:a7:ff:08:00 SRC=192.168.122.1
DST=192.168.122.51 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=22836 DF PROTO=TCP
SPT=41698 DPT=80 WINDOW=64240 RES=0x00 SYN URGP=0
[ 4153.775211] BL_UPDATE IN=eth0 OUT=
MAC=52:54:00:01:89:30:52:54:00:5d:a7:ff:08:00 SRC=192.168.122.1
DST=192.168.122.51 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=22837 DF PROTO=TCP
SPT=41698 DPT=80 WINDOW=64240 RES=0x00 SYN URGP=0
The first packet skips the --update rule -- because it isn't in the blacklist yet -- and then hits the --set rule, so we see the BL_ADD log output. The following packets stop at the --update rule, because now they're in the blacklist, so we see the BL_UPDATE log output.
With this configuration, a connection from 192.168.122.1 results in an entry like this in /proc/net/xt_recent/BLACKLIST:
src=192.168.0.0 ttl: 64 last_seen: 4303109595 oldest_pkt: 13 4303017951, 4303018971, 4303035387, 4303035595, 4303035803, 4303036211, 4303037019, 4303038685, 4303041947, 4303048411, 4303061723, 4303108569, 4303109595
Note that the src address is 192.168.0.0; our --mask argument was applied to transform the original 192.168.122.1 source address.
If we remove the --set rule, so that we have instead:
iptables -N bl_add
iptables -A bl_add -j LOG --log-prefix "BL_ADD "
iptables -A bl_add -j DROP
iptables -N bl_update
iptables -A bl_update -j LOG --log-prefix "BL_UPDATE "
iptables -A bl_update -j DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m recent --name BLACKLIST --update --mask 255.255.0.0 --seconds 20 -j bl_update
A connection to port 80 from 192.168.122.1 results in no log output, and no entries in /proc/net/xt_recent/BLACKLIST. The --update rule does nothing if the source address hasn't previously been added to BLACKLIST with a --set rule.
In case it's useful, the iptables-save output for the working configuration is:
*filter
:INPUT ACCEPT [31:2152]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [16:1520]
:bl_add - [0:0]
:bl_update - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m recent --update --seconds 20 --name BLACKLIST --mask 255.255.0.0 --rsource -j bl_update
-A INPUT -i eth0 -p tcp -m tcp --dport 80 -m recent --set --name BLACKLIST --mask 255.255.255.255 --rsource -j bl_add
-A bl_add -j LOG --log-prefix "BL_ADD "
-A bl_add -j DROP
-A bl_update -j LOG --log-prefix "BL_UPDATE "
-A bl_update -j DROP
COMMIT
| iptables recent --mask not working |
1,371,236,423,000 |
I am restricting the traffic to specific port number using the below firewall rule.
/sbin/iptables -A INPUT -p tcp --destination-port <port_num> -j DROP
After sometime i want to allow traffic, so adding the below firewall rule.
/sbin/iptables -A INPUT -p tcp --destination-port <port_num> -j ACCEPT
Is it correct or i have to delete the first rule before adding the second. if i dont delete the first rule,both rules are present in the INPUT chain. so which one is considered ? This is in CentOS7, Looking forward for your advise.
|
The -A flag appends to the set of rules. Using -I inserts a rule either at the beginning of the chain or at the numbered position. Rules are processed in order, so the first rule you added will be processed first and the second will never be actioned.
You can see the full set of rules for your INPUT chain with iptables -nvL INPUT.
Since you're on CentOS you might want to use its standard firewall tool, firewalld instead of the low-level iptables.
Also see iptables and RETURN target for an explanation of rules that terminate a chain and those that don't.
| Which firewall rule is considered if i 'drop' first then later adding 'accept' rule. drop or accept? |
1,371,236,423,000 |
I want to check if I can connect to Rspamd's Fuzzy port and have a very strange problem - I can ping a the host and get an answer (0% packet loss). But when I try to telnet him, I get "No route to host":
# telnet 88.99.142.95 11335
Trying 88.99.142.95...
telnet: Unable to connect to remote host: No route to host
And the same with nc:
nc -vz 88.99.142.95 11335
mail.highsecure.ru [88.99.142.95] 11335 (?) : No route to host
Sure, at first glance this looks like a firewall problem, but refer to the following output (the firewall is completely off - better said, there are no blocking rules):
# iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
# iptables -v -n -L
Chain INPUT (policy ACCEPT 98 packets, 6560 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 64 packets, 5736 bytes)
pkts bytes target prot opt in out source destination
I'm on a server virtual machine with Debain 10.
Has anyone an idea where the problem might be?
|
The target port is blocked by the target firewall (at least for your and my IP addresses).
If you run tcpdump -i any -n icmp then you see a host unreachable - admin prohibited ICMP packet.
| Ping works, but I get 'No route to host' even though my firewall is off |
1,371,236,423,000 |
As you can see from the screenshot of GCP firewall rule page, should I remove ICMP Protocol from firewall rules base on security concern? Will it lower the chance of being attacked?
I'm using CentOS 7. I added net.ipv4.icmp_echo_ignore_all=1 to /etc/sysctl.d. Does this have the same effect as deleting the ICMP Protocol from GCP firewall rules page?
|
As you can see from the screenshot of GCP firewall rule page, should I remove ICMP Protocol from firewall rules base on security concern? Will it lower the chance of being attacked?
Opinions differ about this, but it is generally not considered a security risk to accept ICMP packets.
I'm using CentOS 7. I added net.ipv4.icmp_echo_ignore_all=1 to /etc/sysctl.d. Does this have the same effect as deleting the ICMP Protocol from GCP firewall rules page?
No. There are several types of ICMP requests. Ping or echo requests are just one of them. The setting icmp_echo_ignore_all only disables ping responses, while blocking ICMP in the firewall will block all ICMP traffic, ping and all others. This will cause problems, as ICMP packets are sometimes necessary for proper operation.
| Should I remove ICMP Protocol from firewall rules base on security concern? |
1,371,236,423,000 |
My server (on which bellow iptables rules are loaded) has the IP 192.168.3.110.
There is another computer in my LAN with IP 192.168.3.106.
I'm trying to redirect requests to my server on port 80 to 192.168.3.106.
I have the following iptables file which is loaded in my CentOS 7 server:
*nat
:PREROUTING DROP
:INPUT DROP
:OUTPUT DROP
:POSTROUTING DROP
-A PREROUTING -m state --state RELATED,ESTABLISHED -j ACCEPT
-A PREROUTING -p tcp -m state --state NEW --dport 22 -j ACCEPT
-A PREROUTING --dst 192.168.3.110 -p tcp --dport 80 -j DNAT --to-destination 192.168.3.106
-A PREROUTING -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
-A OUTPUT --dst 192.168.3.110 -p tcp -m state --state NEW --dport 80 -j DNAT --to-destination 192.168.3.106
-A OUTPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A POSTROUTING -m state --state RELATED,ESTABLISHED -j ACCEPT
-A POSTROUTING -p tcp -m state --state NEW --dport 22 -j ACCEPT
-A POSTROUTING --src 192.168.3.0/24 --dst 192.168.3.106 -p tcp --dport 80 -j SNAT --to-source 192.168.3.110
-A POSTROUTING -o lo -j ACCEPT
COMMIT
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
-A OUTPUT -p tcp --sport 22 -j ACCEPT
-A OUTPUT -p tcp -j ACCEPT
-A OUTPUT -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
COMMIT
Basically I'm doing the following (at least that's how I understand it):
enable ssh-ing
enable TCP on port 80
DNAT and SNAT packets so that I achieve the desired behavior.
Question: I don't understand why, when I make a call from my server to itself, i.e. 192.168.3.110, I get a response.
That's how I understand that things should work in this case:
curl http://192.168.3.110 - don't forget that I execute this from my server, with IP 192.168.3.110
packet is going to OUTPUT chain from nat table, where it is DNATed
packet is going to POSTROUTING chain from nat table, where it is SNATed
my Apache from 192.168.3.106, is answering to my request.
packet is reaching PREROUTING chain from nat table, where it should be DNATed
packet is forwarded and thrown somewhere.
All seems to work as expected, except 5 and 6. With other words, I receive the response from server. Can anybody explain me where is my logic broken?
|
iptables nat tables are only traversed for the first packet of a (psuedo-)connection. Later packets are mapped (or left alone) according to the mappings established by the first packet.
| Iptables not working as I expect: response package not DNATed as expected with DNAT in PREROUTING |
1,371,236,423,000 |
I just noticed that my server is being blocked for rsync from a firewall outside of my server, so I can't rsync to any target. Now, I would also like to know what are all the ports that are being blocked by that firewall.
Is there any way to use nmap to do that? I know I can use nmap to scan the opened ports in a specific target, but what I want is to know what ports are closed in my server to send packets out.
|
No, you can not nmap to scan one computer from the same computer.
By definition, packets won't travel, and packets traveling is the whole base of the internet.
You need a router, printer, light-bulb or external computer that could run some commands and use it to look back to that computer.
I believe that you can send packets going out (to the outside) from any port to see which ports are being blocked in the outgoing direction without any security issue. But even to do that, you need some external address to send your packets to.
Trying to scan from outside to such firewalled computer may easily be seen as an attack and you may get banned or blocked even more than you are now. To actually perform such scan from the outside the best is to inform and ask for permission from the network managers in such system.
| How to scan outbound closed ports with nmap? |
1,371,236,423,000 |
If a service (or port) is blocked in both TCPwrapper and Iptables, which will block the request first and why?
|
Answer:
Its Iptable(firewall).
Why?
In simple words, TCPwrapper comes in between firewall and network Services.
In the OSI model, the TCPwrapper works in Application layer while iptable works mostly in Transport layer.
Source:: Access Control Using TCP-wrappers
| Which one will block first? tcp-wrapper or Iptables? |
1,371,236,423,000 |
I deleted the ufw files in /etc/ufw/, so I can start from scratch with a new generated port file. But after I deleted ufw per apt-get and reinstalled it, the files do not get generated. So what am I now supposed to do?
I get many connections from "outside", like 122.246.16.251:80 to every single port of my local ubuntu-server. With ufw I want to prevent this. The question is how.
So my primary question is: How do I get new generated ufw-files after delting them?
And my secondary question is: How can I block, maybe every IP from middle-east and only let europe IPs connect to my server.
|
remove and install ufw, but you need to use apt-get remove --purge
sudo apt-get remove --purge ufw
| I need to regenerate the ufw files |
1,371,236,423,000 |
I am trying to follow this answer on OS X 11.x
block return from any to 192.0.2.2
The console displays :
-bash: block: command not found
So, I tried to install it using brew:
brew install block
However, I got another error .
How to install this firewall utility?
|
On recent versions of OS X, pf is installed and running by default. The linked question is referring to changing the pf configuration, not installing a new utility. Modifying a firewall on a production system is not something which should be done without reading the documentation (man pf.conf , man pfctl).
To add that block line (or experiment with other configuration changes), you would add it to the configuration file /etc/pf.conf with your preferred editor, and then reload the firewall configuration with
$ sudo pfctl -f /etc/pf.conf
| block command line not found |
1,371,236,423,000 |
I am using the command below to allow all traffic from hosts on my internal network but it says "iptables v1.4.18: Couldn't load target `ALLOW':No such file or directory". What is the problem here?
iptables -A input -s 192.168.1.0/24 -j ALLOW
|
The target isn't ALLOW it should be ACCEPT.
$ iptables -A INPUT -s 192.168.1.0/24 -j ACCEPT
excerpt iptables man page
TARGETS
A firewall rule specifies criteria for a packet, and a target. If the
packet does not match, the next rule in the chain is the examined; if it
does match, then the next rule is specified by the value of the target,
which can be the name of a user-defined chain or one of the special values
ACCEPT, DROP, QUEUE, or RETURN.
ACCEPT means to let the packet through. DROP means to drop the packet on
the floor. QUEUE means to pass the packet to userspace (if supported by the
kernel). RETURN means stop traversing this chain and resume at the next
rule in the previous (calling) chain. If the end of a built-in chain is
reached or a rule in a built-in chain with target RETURN is matched, the
target specified by the chain policy determines the fate of the packet.
| iptables couldn't load target allow |
1,371,236,423,000 |
I've been poking around with KVM VM's on Centos 6.4 not having an internet connection on my VM's, I found something curious:
Upon booting the machine, iptables has rules in the FORWARD chain to allow traffic through to the VM's and all is well. When I run service iptables restart, however, it looks like it pulls the config rules from /etc/sysconfig/iptables (default settings which reject all forwarding) and thus, I've been relegated to either dropping the firewall completely on the physical host or rebooting to get the FORWARD rules added so it works again.
Edit:
Indeed, I could just modify the firewall rules myself to allow it, but isn't the focus of this question. I'm more focused on the following question #1:
My questions are:
At what point (or by what mechanism) are these FORWARD rules added in?
How can I recover the FORWARD rules without rebooting the machine?
Quite frankly, I'm not even sure where to start searching for this issue. I found this page that says to modify /etc/sysctl.conf with the following variables which allegedly make netfilter ignore traffic to bridged connections:
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
The problem with that is that my sysctl.conf is already set as such and netfilter still does its thing, happily blocking everything to the VM's.
|
KVM itself doesn't do anything but run the VM. iptables rules are put in place by libvirt, (or the qemu-ifup scripts if you are doing things hardcore and manual)
In any case, if you want to avoid the iptables complication, don't use VMs in a NAT config, and switch to using a bridge or OVS instead.
OVS config
Bridged networking
| How does KVM set its own netfilter rules? |
1,371,236,423,000 |
I have this configuration:
source: https://www.lucidchart.com/publicSegments/view/5256a1e5-afb0-4c7a-96fa-35750a00527d/image.png
Basically, I have to reach a service which is running on the virtual machine with IP address 192.168.0.20 from a remote machine; this service is reachable on the port 80 and is working via a browser. However, I can't modify any firewall configuration on the hypervisor (the physical machine I can reach with its public IP).
|
You need to forward the port by a user space program.
I can recommend you socat, e.g.
socat TCP4-LISTEN:80,fork,reuseaddr TCP4:192.168.0.20:80
It seems that you do not have root rights on the hypervisor. In this case you need to choose a port above 1023 for listening on the hypervisor.
See following question for more options (like redir): https://serverfault.com/questions/252150/port-forwarding-on-linux-without-iptables
| Reach service on VM with private address |
1,371,236,423,000 |
Is the iptables file in Fedora 17 moved from /etc/init.d/ to /etc/sysconfig/? I need do some patching to the iptables file to solve the firewall problem (Setting chains to policy ACCEPT: security raw nat mangle filter [FAILED]).
|
The firewall in F17 has changed from iptables to FirewallD.
The init daemon was also replaced with systemd in F15, so you'll see many of the old init.d bash scripts are not there anymore.
Here's some places to get started:
https://fedoraproject.org/wiki/FirewallD
https://ask.fedoraproject.org/question/7350/what-is-the-best-way-to-configure-the-fedora17-firewall/
| Missing iptables file on directory /etc/init.d/ (Fedora 17) |
1,371,236,423,000 |
I was reading this interesting article today: http://www.moserware.com/2009/06/first-few-milliseconds-of-https.html
A crazy thought came to mind...Is it possible to write an iptable rule that only redirects https handshake requests?
|
No. You can't know it's a HTTPS handshake until the connection is open. At that point, it's too late to redirect it. The SYN packet doesn't tell you what's going to be transmitted; that's why we have port numbers to begin with.
| iptable rule to redirect only https handshake? |
1,371,236,423,000 |
I'm debugging a firewall .service unit and a few questions arise.
One of those questions is the unit's best service type, either exec or oneshot. Virtually no comparisons of the two appear in my searches, probably because exec is a relatively recent addition to systemd (v.249 IIRC).
By way of background, the unit (call it iptables.service) is intended to activate and configure the firewall by running a Bash script (call it iptables.sh) before the network is up (i.e., before network-pre.target), e.g.,
ExecStart=/bin/bash -c '/home/locsh/iptables.sh'
Type=oneshot has the advantage of not entering the "active" state, so it subsequently can be restarted or reactivated, e.g., by a timer unit. It also is the more common of the two types in most examples, albeit without explanation.
Type=exec has the advantage that it will delay startup of follow-up units until the main service has been executed. This seems to make perfect sense for a firewall .service unit because the network should depend on the script running successfully and remain down otherwise, e.g., if the script temporarily can't be read because somehow the relevant .mount unit hasn't yet activated.
Restart=on-failure seems to be an obvious and prudent addition in either case.
The first question is whether one or the other might better for any reason.
The second question is whether Type=exec, because it delays the start of follow-up units, might introduce a subtle ordering cycle in some edge cases, either with or without "Restart=on-failure", in part because the unit's ordering dependency
Before=network-pre.target
is relatively early in the boot process.
|
You want type=oneshot. If you use type=exec, other services will be able to start before the firewall is configured. From the systemd.service man page, for exec:
...Or in other words: simple proceeds with further jobs right after fork() returns, while exec will not proceed before both fork() and execve() in the service process succeeded.
And for oneshot:
Behavior of oneshot is similar to simple; however, the service manager will consider the unit up after the main process exits.
In other words, with Type=exec, systemd considers the service to
be "up" once the process has successfully started, while
for Type=oneshot, systemd considers the service to be "up" once
the process has successfully completed.
| systemd Firewall .service Unit: Type=exec or Type=oneshot? |
1,371,236,423,000 |
I am using Ubuntu 20.04.3 LTS, although this question is probably not specific to Ubuntu but to any system using ufw.
I am setting up a rule for VNC vino connections.
I meant to do that via a configured app.
I created /etc/ufw/applications.d/vino-server with the following contents
[Vino Server]
title = “Vino VNC Server”
description = “Vino - Default Ubuntu VNC server”
ports=5900,5901/tcp
and then
$ sudo ufw allow app "Vino Server" from 192.168.0.0/24
ERROR: Need 'from' or 'to' with 'app'
How can I solve this error?
I executed then
$ sudo ufw allow from 192.168.0.0/24 proto tcp to any port 5900
which added one line to the ufw status (see below), and finally allowed connection via remmina. So it seems I am ok to connect, and only missing the app-way configuration/allowing.
$ sudo nmap localhost
Starting Nmap 7.80 ( https://nmap.org ) at 2021-11-19 08:03 -03
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0000070s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
631/tcp open ipp
5900/tcp open vnc
Nmap done: 1 IP address (1 host up) scanned in 0.18 seconds
$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22/tcp ALLOW IN Anywhere
5900/tcp ALLOW IN 192.168.0.0/24 <--- THIS LINE ADDED
22/tcp (v6) ALLOW IN Anywhere (v6)
$ sudo ss -ltnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 5 127.0.0.1:631 0.0.0.0:* users:(("cupsd",pid=727,fd=7))
LISTEN 0 128 127.0.0.1:6010 0.0.0.0:* users:(("sshd",pid=9845,fd=11))
LISTEN 0 5 0.0.0.0:5900 0.0.0.0:* users:(("vino-server",pid=6594,fd=12))
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=704,fd=13))
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=7138,fd=3))
LISTEN 0 5 [::1]:631 [::]:* users:(("cupsd",pid=727,fd=6))
LISTEN 0 128 [::1]:6010 [::]:* users:(("sshd",pid=9845,fd=10))
LISTEN 0 5 [::]:5900 [::]:* users:(("vino-server",pid=6594,fd=11))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=7138,fd=4))
|
From man ufw:
ufw [--dry-run] [rule] [delete] [insert NUM] [prepend] allow|deny|reject|limit
[in|out [on INTERFACE]] [log|log-all] [proto PROTOCOL] [from ADDRESS [port PORT | app APPNAME ]]
[to ADDRESS [port PORT | app APPNAME ]] [comment COMMENT]
Accordingly, you have to specify from first.
sudo ufw allow from 192.168.0.0/24 app "Vino Server"
| Ufw allow app: ERROR: Need 'from' or 'to' with 'app' |
1,371,236,423,000 |
From the nftables Quick reference:
family refers to a one of the following table types: ip, arp, ip6,
bridge, inet, netdev.
and
type refers to the kind of chain to be created. Possible types are:
filter: Supported by arp, bridge, ip, ip6 and inet table families.
route: Mark packets (like mangle for the output hook, for other hooks
use the type filter instead), supported by ip and ip6.nat: In order
to perform Network Address Translation, supported by ip and ip6.
From another document which explains how to configure chains:
The possible chain types are:
filter, which is used to filter packets. This is supported by the arp,
bridge, ip, ip6 and inet table families.route, which is used to
reroute packets if any relevant IP header field or the packet mark is
modified. If you are familiar with iptables, this chain type provides
equivalent semantics to the mangle table but only for the output hook
(for other hooks use type filter instead). This is supported by the
ip, ip6 and inet table families.nat, which is used to perform
Networking Address Translation (NAT). Only the first packet of a given
flow hits this chain; subsequent packets bypass it. Therefore, never
use this chain for filtering. The nat chain type is supported by the
ip, ip6 and inet table families.
Hence, according to at least two authoritative references, no chain type is supported by the netdev family. Given that, how can we use the netdev family at all?
|
I am new one, but also interested in nftables rules. I found in nftables wiki: "The principal (only?) use for this (netdev) family is for base chains using the ingress hook, new in Linux kernel 4.2." More info here, in the end of article: https://wiki.nftables.org/wiki-nftables/index.php/Nftables_families
Ingress hook allows you to filter L2 traffic. It comes before prerouting, after the packet is passed up from the NIC driver. This means you can enforce very early filtering policies. This very early location in the packet path is ideal for dropping packets associated with DDoS attacks.
When adding a chain on ingress hook, it is mandatory to specify the device where the chain will be attached
Source: https://www.datapacket.com/blog/securing-your-server-with-nftables
How to specify the device can be found here:
How to use variable for device name when declaring a chain to use the (netdev) ingress hook?
| What chain types are supported by the nftables NETDEV family? |
1,371,236,423,000 |
This question is in a way related this and this
My question is about blocking incoming connections using iptables. I read different posts in unix.stackexchange.com and got a basic understanding of iptables. But I do not understand some particular points. Any help is appreciated.
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -P INPUT DROP
I wanna use this code. It has to block all incoming connections (all ports will be closed for an outsider) except the responses for requests sent by me. This was simple I thought.
will incoming ICMP ping requests be blocked by the above shown code ? If not, why?
if above shown code does not block ICMP ping requests, adding iptables -I INPUT -j DROP -p icmp --icmp-type echo-request will block it?
can port scans from a blocked ip can get information about my computer?
should I add specific rules like -p tcp --tcp-flags FIN,SYN FIN,SYN -j DROP to block specific flood attacks or my first code handles it?
|
Yes. All inbound traffic that isn't post of an existing session will be blocked
Only if (a) you've connected to that rogue host, or (b) it knows you should be there and by your lack if response it can infer you've a firewall
You're already covered by #1
| IP Tables - Blocking Incoming Traffic |
1,371,236,423,000 |
I assume the answer to this question is "no", but I would imagine there is some alternative method of achieving this.
What I want to do is add a second, even stronger password, for when I login with ssh externally. (From outside my private network.)
Is it possible to do this?
I envision something like this; some kind of option in iptables which requires the user to enter a password in order to forward traffic from an external source via port 22. I'm not aware of any such feature in iptables for example, and I assume it is not possible since iptables makes routing decisions based on the headers of ip packets, whereas ssh information is contained inside an encrypted data payload inside the ip/tcp header(s).
Presumably something like this is used in enterprise grade equipment and organizations?
What about dual factor authentication, is something like that possible as an alternative?
Sorry for the slightly vague/unfocused question, I'm by no means experienced in this area.
|
Best practise: Use key-based authentication, disable password-based authentication.
The best password-way to secure your SSH daemon is to disable password authentication altogether and force the use of key-based authentication.
This is considered more secure by a large factor and there is no more securing by password necessary.
Of course, do create keys and try logging in by keys before disabling password-based logins!
Documentation: SSH.com: key-based authentication Digital Ocean: ssh key-based auth
General SSH hardening tips: Cyberciti Jason Rigden (includes 2FA) Security Trails
| Is it possible to add a strong external password to iptables on port 22? |
1,371,236,423,000 |
I have added a DNAT entry (in the host) for a port (say 30001) in PREROUTING using iptables
$ sudo iptables -t nat -A PREROUTING -p tcp --dport 30001 -j DNAT --to-destination <my guest vm ip>:80
Note: Above I have tried a port forwarding technique to allow ingress to guest vm.
Is it possible for a host process to bind to the port 30001 after applying the above rule? Will Linux allow this or block by saying it is already in use?
|
Yes, binding a port is part of the network stack, which is separate from netfilter where iptables belongs to. netfilter will not care or be aware of this new listening port and the network stack will not be informed that there will be something special about it done in its back later.
So it's fine to have a process bind to port 30001/tcp. It won't be reachable from remote with your rule, but will still be usable locally: a local (non-routed) access from the host to itself follows the chain OUTPUT for emitting, then when it's looped back, arrives directly in INPUT without hitting PREROUTING, so your nat/PREROUTING rule would not be executed in this case.
This schematic should help understand how it's working for the DNAT / routed case (the non-routed local case isn't shown as clearly though). A remote access would follow PREROUTING -> routing decision -> INPUT -> local process, but in your case with your DNAT rule it will take the path PREROUTING -> routing decision -> FORWARD -> ... so will not reach the local process. So as long you don't add the equivalent rule in nat/OUTPUT, there's still an use for this case. In any case, usable or not, you can still bind to this port.
| Is it possible to bind to a port that has a entry for DNAT in iptables? |
1,371,236,423,000 |
I’m looking into a solution to prevent some application to accessing the internet when I’m connected to a specific wifi access point. My exact use case is that I would like to disable dropbox, spotify and similar apps to use all my data when connecting through my phone tethering.
The solution could be at another level than network itself, but I’d prefer to avoid the "killing the apps" solution.
I’m running archlinux but if a good solution for another distro is available, it can surely give me a good direction.
|
The problem can be split in two parts:
identify when a restricted access point (tethering's) is in use
identify which outgoing packets belong to restricted applications
Combining the two together will identify packets belonging to restricted applications going out using the restricted access point (in order to drop such packets).
Preparation
Some glue before rather than after explanations, so typing everything in order just works.
Use two iptables chains: one doing the action (blocksomeapps), the other (tetheractivated) to call it and that can be easily flushed:
iptables -N tetheractivated
iptables -N blocksomeapps
iptables -I OUTPUT -j tetheractivated
1. Access point
This answer assumes only one access point is in use at any moment, and that this access point is using an already known network interface name (wlan0). It also assumes wpa_supplicant will be the low level daemon handling it. It doesn't matter if standalone or a backend of NetworkManager, as long as it can be queried with wpa_cli and its -a (action) option.
action script myaction.sh:
#!/bin/sh
TETHERSSID='My Tethering'
case "$2" in
'CONNECTED')
ssid="$(wpa_cli -p "$WPA_CTRL_DIR" -i "$1" get_network "$WPA_ID" ssid)"
# Note: ssid's value already comes with an added pair of double quotes around:
# adding one as well
if [ "$ssid" = \""$TETHERSSID"\" ]; then
iptables -A tetheractivated -j blocksomeapps
fi
;;
'DISCONNECTED')
iptables -F tetheractivated
;;
esac
This script (which must be executable) is then used as an event loop by keeping this program running:
wpa_cli -a myaction.sh
This will then make the iptables chain blocksomeapps appear in the packet path when connected to the target SSID, and be removed from packet path when (any SSID is) disconnected.
2. Restricted applications
This is more difficult to handle. There are various methods to identify a packet belonging to a specific process, requiring anyway additional preparation. Some methods require more things than others.
Some examples:
the packet could be enqueued to an userspace application doing additional checks (the program has to be written, probably in C or python)
the restricted processes can be run as a separate user: quite easy to deal with.
the restricted processes could be run from their own dedicated network namespace: once done, quite easy to deal with. Putting them there in the first place (involving configuration and probable root access and back to user access to start them) can give some trouble.
Here's a quite simple method found in this Q/A: Block network access of a process?
Classify packets from the same net_cls cgroup with a value that can be looked up in iptables (in addition to the main target: Traffic Controller tc).
Create the specific net_cls group and give it a specific classid:
# mkdir -p /sys/fs/cgroup/net_cls/blocksomeapps
# echo 42 > /sys/fs/cgroup/net_cls/blocksomeapps/net_cls.classid
Identify target processes (threads must be included), and add them to the group (by writting to tasks one pid (or tid) at a time. This could be racy if processes change a lot, so it should better done during startup of application. Of course once done, children automatically stay in the same group.
Example with firefox (which uses multiple threads within multiple processes, so pgrep needs --lightweight to output all thread ids):
# for i in $(pgrep --lightweight -f firefox); do echo $i > /sys/fs/cgroup/net_cls/blocksomeapps/tasks; done
( pid/tid to be removed from this group should be written to the parent /sys/fs/cgroup/net_cls/tasks )
Add the blocking rule in the empty chain blocksomeapps prepared before:
# iptables -A blocksomeapps -m cgroup --cgroup 42 -j DROP
To block only packets going through wlan0, use instead:
# iptables -A blocksomeapps -o wlan0 -m cgroup --cgroup 42 -j DROP
but then indirect activity generated by those applications, such as DNS queries to a local DNS caching daemon, might still generate some data traffic since for example the DNS caching daemon wouldn't be itself blocked.
Notes:
The SSID part could be improved (and deal with multiple simultaneous access points) by involving route checks somewhere, but would rapidly become very complex. The simple myaction.sh script wouldn't then be enough (because knowing the SSID we connected to gives nothing about the network layer not even configured yet).
Nowadays, cgroups have already been mounted and configured, probably by systemd or cgmanager. It's out of this Q/A scope to configure this, if it's not available.
cgroups v1 are slowly being replaced by cgroups v2, so this answer should be adapted to v2 someday.
Also this method will probably be incompatible (or at least difficult to use) with containers or network namespaces created with ip netns just because both apply restrictions to the use of cgroups (for ip netns: as ip netns exec ... remounts /sys/, the /sys/fs/cgroup tree becomes unavailable, and it can't really be mounted twice).
All output packets cross the cgroup match. tetheractivated could be inserted after the usual ESTABLISHED stateful rule to decrease load, but then already established flows wouldn't be dropped, which could keep them working for some time depending on the application. This could be helped with conntrack (-D or -F).
Instead of blocking traffic with iptables (or nftables) tc (and its cgroup filter) could be used to apply severe bandwidth restrictions. Just remember that while output traffic is in full control, incoming traffic is not: once a packet is received (and associated to the same flow than previous outgoing), even if dropped, data was already spent.
| Blocking internet access to some application with a specific wifi |
1,577,654,170,000 |
I have a lot of records in my firewall log that are related to HTTPS traffic. For some reason incoming connections are being made to ephemeral ports and they are blocked by my firewall because these ports are closed.
dec 08 11:49:12 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x08 PREC=0x20 TTL=51 ID=0 DF PROTO=TCP SPT=443 DPT=34004 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:49:12 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x08 PREC=0x20 TTL=51 ID=0 DF PROTO=TCP SPT=443 DPT=34004 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:49:12 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x08 PREC=0x20 TTL=51 ID=0 DF PROTO=TCP SPT=443 DPT=34004 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:49:24 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=235 ID=25611 DF PROTO=TCP SPT=443 DPT=43402 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:49:24 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=235 ID=25612 DF PROTO=TCP SPT=443 DPT=43402 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:49:24 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=233 ID=53730 DF PROTO=TCP SPT=443 DPT=52450 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:49:24 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=233 ID=53731 DF PROTO=TCP SPT=443 DPT=52450 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:49:24 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=235 ID=57942 DF PROTO=TCP SPT=443 DPT=46798 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:49:24 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=235 ID=25613 DF PROTO=TCP SPT=443 DPT=43402 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:49:24 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=235 ID=57944 DF PROTO=TCP SPT=443 DPT=46798 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:49:39 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=232 ID=56694 DF PROTO=TCP SPT=443 DPT=52468 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:50:14 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=235 ID=57810 DF PROTO=TCP SPT=443 DPT=52484 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:50:14 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=235 ID=57811 DF PROTO=TCP SPT=443 DPT=52484 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:50:35 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=235 ID=42912 DF PROTO=TCP SPT=443 DPT=54426 WINDOW=0 RES=0x00 RST URGP=0
dec 08 11:50:54 hostname kernel: [UFW BLOCK] IN=enp31s0 OUT= MAC=- SRC=- DST=192.168.1.129 LEN=40 TOS=0x00 PREC=0x00 TTL=233 ID=40448 DF PROTO=TCP SPT=443 DPT=38152 WINDOW=0 RES=0x00 RST URGP=0
Note that the traffic comes from non RFC1918 IPs, they have been left out of the logs here.
What could be the reason for these incoming connections?
|
... SPT=443 DPT=54426 ... RST URGP=0
These are not incoming connections. These are RST packets. These happen for example your client writes data to the server while the server has already shutdown the connection. It is unknown what exactly happens in your specific case though and if a proper iptables rules which allows packets for ESTABILISHED connections would let these packets pass.
| HTTPS connections are generating incoming connections |
1,577,654,170,000 |
I want to install gufw on my Fedora, but I do not know how to do that.
I tried to install with the dnf package manager command but it doesn't work and gets this output:
No match for argument: gufw
Error: Unable to find a match
So, I did an apt-get and again I got negative result:
E: Couldn't find package gufw
How can I successfully install gufw?
I want to control each app's access to the internet, so is there any firewall app other than gufw?
|
You need the rpmsphere software repository which contains the gufw package.
The following works for Fedora 30, with root rights:
# install rpmsphere repository
rpm -Uvh 'https://github.com/rpmsphere/noarch/blob/master/r/rpmsphere-release-30-1.noarch.rpm?raw=true'
# install gufw
dnf install gufw
| How can I install gufw on fedora? |
1,577,654,170,000 |
Basically I have a armbian distro configured as NAT where wlan0 is the internal interface and eth0 is the "pubic" interface that provides internet (this set is provided out of the box by armbian-config).
My devices connect over wlan0 grabbing an IP, say 172.24.1.114
I have added a VPN to a remote network resulting in the creation of ppp0, with IP 10.10.10.12
Having these info, what I want to achieve is:
Only one IP (e.g. 172.24.1.114) has to always go towards ppp0 (that is all traffic back and forth should go to ppp0, so I can either reach machines and navigate on internet with the remote IP)
All other IPs can normally go towards eth0
Starting from the configured NAT from armbian-config I have added the extra iptables rules:
-A FORWARD -i wlan0 -o ppp0 -j ACCEPT (this is before -A FORWARD -i wlan0-o eth0 -j ACCEPT created by armbian-config)
-A POSTROUTING -o ppp0 -j MASQUERADE (order shouldn't impact with -A POSTROUTING -o eth0 -j MASQUERADE created by armbian-config)
-A FORWARD -i ppp0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT (just to be sure!)
These extra rules + the one from armbian-config seem to work all most well:
From 172.24.1.114 client I can see content of a remote web server, say http://10.10.10.20 ( so apparently it goes thru ppp0)
From 172.24.1.114 client I can navigate on internet, but unfortunately checking the IP I go out with (using a geo ip website), it still results the one from eth0
All other clients correctly navigate going out thru eth0
So to summarize it, I can now reach the remote network over VPN for that IP but it is not able to navigate thru ppp0
As last try I found the way to set rule policies, like in this guide (http://wiki.wlug.org.nz/SourceBasedRouting), so I can specify that source IP 172.24.1.114 goes to custom table other than the main one; then I added in this new table the default gateway of 10.10.10.1 dev ppp0. This leads to lack of web navigation for that IP.
|
I have resolved all.
First the required iptables' rules are (these give access to the remote VPN's machines):
-A FORWARD -i wlan0 -o ppp0 -j ACCEPT
-A POSTROUTING -o ppp0 -j MASQUERADE
Then, to indicate which IP or range of IPs have to have a different route, you need policy rules:
open /etc/iproute2/rt_tables and put your entry (ID tablename):
100 my_custom_table
ip rule add from 172.24.1.114/24 table my_custom_table (tells to go to another table other than the main one for the source IP 172.x.x.x)
ip route add 172.24.1.0/24 dev wlan0 table my_custom_table (required to receive packets back from ppp0)
ip route add default via 10.10.10.1 dev ppp0 table my_custom_table (routes packet to the VPN's gateway)
Make sure the firewall on the VPN server allows incoming traffic from VPN IPs.
| NAT a specific IP to go to ppp0 and others to go to eth0 coming from internal wifi interface |
1,577,654,170,000 |
I am running Red Hat Linux 6.2
Trying to install nfs packages using yum
Following is the
repository list
repo id repo name status
base CentOS-6 - Base 6,713
centos CentOS 6 - x86_64 0
cloudera-cdh5 Cloudera's Distribution for Hadoop, Version 5 153
cloudera-gplextras5 Cloudera's GPLExtras, Version 5 9
cloudera-kafka Cloudera's Distribution for kafka, Version 2 4
cloudera-manager Cloudera Manager, Version 5 7
epel Extra Packages for Enterprise Linux 12,513
extras CentOS-6 - Extras 33
rpmfusion-free-updates RPM Fusion for EL 6 - Free - Updates 230
updates CentOS-6 - Updates 142
vmware-tools VMWare Tools 33
repolist: 19,837
When I am giving the command to install nfs packages as follows, it fails -
sudo yum install hadoop-hdfs-nfs3
It fails
Below two errors are shown for each dependency being downloaded -
1
[Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
2
[Errno 256] No more mirrors to try.
Below is the Complete Output of the command -
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* epel: mirrors.isu.net.sa
* extras: centos.excellmedia.net
* rpmfusion-free-updates: mirror.lzu.edu.cn
* updates: mirrors.viethosting.com
Resolving Dependencies
--> Running transaction check
---> Package hadoop-hdfs-nfs3.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be installed
--> Processing Dependency: hadoop = 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 for package: hadoop-hdfs-nfs3-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 for package: hadoop-hdfs-nfs3-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64
--> Running transaction check
---> Package hadoop.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
--> Processing Dependency: hadoop = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-hdfs-fuse-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-0.20-mapreduce-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-0.20-mapreduce-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-libhdfs-devel-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-conf-pseudo-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-client-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-yarn-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-yarn-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-mapreduce-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-mapreduce-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
---> Package hadoop.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
base/filelists_db | 6.4 MB 00:54
cloudera-cdh5/filelists | 440 kB 00:30
cloudera-gplextras5/filelists | 5.6 kB 00:00
cloudera-kafka/filelists | 2.4 kB 00:00
cloudera-manager/filelists | 128 kB 00:08
epel/filelists | 7.3 MB 09:14
extras/filelists_db | 24 kB 00:00
https://mirror.lzu.edu.cn/rpmfusion/free/el/updates/6/x86_64/repodata/6ff3fb17129839139ff7d53fedce33cb7c58bce2c4ac21c9eac9a809403786b8-filelists.sqlite.bz2: [Errno 14] problem making ssl connection
Trying other mirror.
rpmfusion-free-updates/filelists_db | 124 kB 00:00
http://mirrors.viethosting.com/centos/6.10/updates/x86_64/repodata/7982c733d4660661cd9b10a58eabfba7d6b16879c57850ad2c1cb95f403a7f3f-filelists.sqlite.bz2: [Errno 12] Timeout on http://mirrors.viethosting.com/centos/6.10/updates/x86_64/repodata/7982c733d4660661cd9b10a58eabfba7d6b16879c57850ad2c1cb95f403a7f3f-filelists.sqlite.bz2: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')
Trying other mirror.
updates/filelists_db | 921 kB 00:03
vmware-tools/filelists | 4.0 kB 00:00
---> Package hadoop-hdfs.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-hdfs-namenode-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-hdfs-namenode-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-libhdfs-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-httpfs-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-httpfs-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-hdfs-datanode-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-hdfs-datanode-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-hdfs-secondarynamenode-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-hdfs-secondarynamenode-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-hdfs-journalnode-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop-hdfs = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-mapreduce-historyserver-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
---> Package hadoop-hdfs.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
--> Running transaction check
---> Package hadoop-0.20-mapreduce.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-0.20-mapreduce.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-client.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
--> Processing Dependency: hadoop-client = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-kms-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
---> Package hadoop-client.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-conf-pseudo.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-conf-pseudo.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
--> Processing Dependency: hadoop-yarn-nodemanager = 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 for package: hadoop-conf-pseudo-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64
--> Processing Dependency: hadoop-yarn-resourcemanager = 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 for package: hadoop-conf-pseudo-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64
---> Package hadoop-hdfs-datanode.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-hdfs-datanode.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-hdfs-fuse.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-hdfs-fuse.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-hdfs-journalnode.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-hdfs-journalnode.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-hdfs-namenode.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-hdfs-namenode.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-hdfs-secondarynamenode.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-hdfs-secondarynamenode.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-httpfs.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-httpfs.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-libhdfs.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-libhdfs.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-libhdfs-devel.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-libhdfs-devel.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-mapreduce.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-mapreduce.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-mapreduce-historyserver.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-mapreduce-historyserver.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-yarn.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
--> Processing Dependency: hadoop-yarn = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-yarn-proxyserver-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
--> Processing Dependency: hadoop-yarn = 2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 for package: hadoop-yarn-proxyserver-2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6.x86_64
---> Package hadoop-yarn.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
--> Running transaction check
---> Package hadoop-kms.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-kms.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-yarn-nodemanager.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-yarn-nodemanager.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-yarn-proxyserver.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-yarn-proxyserver.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
---> Package hadoop-yarn-resourcemanager.x86_64 0:2.6.0+cdh5.13.0+2639-1.cdh5.13.0.p0.34.el6 will be updated
---> Package hadoop-yarn-resourcemanager.x86_64 0:2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================
Installing:
hadoop-hdfs-nfs3 x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 5.0 k
Updating for dependencies:
hadoop x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 76 M
hadoop-0.20-mapreduce x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 88 M
hadoop-client x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 34 k
hadoop-conf-pseudo x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 8.9 k
hadoop-hdfs x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 24 M
hadoop-hdfs-datanode x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 5.2 k
hadoop-hdfs-fuse x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 22 k
hadoop-hdfs-journalnode x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 5.1 k
hadoop-hdfs-namenode x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 5.4 k
hadoop-hdfs-secondarynamenode x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 5.2 k
hadoop-httpfs x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 17 M
hadoop-kms x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 17 M
hadoop-libhdfs x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 27 k
hadoop-libhdfs-devel x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 10 k
hadoop-mapreduce x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 33 M
hadoop-mapreduce-historyserver x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 5.1 k
hadoop-yarn x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 15 M
hadoop-yarn-nodemanager x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 5.0 k
hadoop-yarn-proxyserver x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 4.9 k
hadoop-yarn-resourcemanager x86_64 2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6 cloudera-cdh5 4.9 k
Transaction Summary
============================================================================================================================================================================
Install 1 Package(s)
Upgrade 20 Package(s)
Total download size: 269 M
Is this ok [y/N]: y
Downloading Packages:
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-0.20-mapreduce-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-client-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-conf-pseudo-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
...
...
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-hdfs-secondarynamenode-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-httpfs-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-kms-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-libhdfs-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-libhdfs-devel-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-mapreduce-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-mapreduce-historyserver-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-yarn-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-yarn-nodemanager-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-yarn-proxyserver-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-yarn-resourcemanager-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 401 Authorization Required"
Trying other mirror.
Error Downloading Packages:
hadoop-libhdfs-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-libhdfs-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-conf-pseudo-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-conf-pseudo-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-hdfs-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-hdfs-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-yarn-proxyserver-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-yarn-proxyserver-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-hdfs-datanode-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-hdfs-datanode-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-kms-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-kms-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
...
...
...
hadoop-yarn-nodemanager-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-yarn-nodemanager-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-mapreduce-historyserver-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-mapreduce-historyserver-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-hdfs-journalnode-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-hdfs-journalnode-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-yarn-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-yarn-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-hdfs-fuse-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-hdfs-fuse-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-httpfs-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-httpfs-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-hdfs-nfs3-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-hdfs-nfs3-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
hadoop-yarn-resourcemanager-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64: failure: RPMS/x86_64/hadoop-yarn-resourcemanager-2.6.0+cdh5.15.1+2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm from cloudera-cdh5: [Errno 256] No more mirrors to try.
As a workaround I am downloading the dependent urls through 'wget' triggered through bash (with http username and http password of my work network to pass through the firewall)
links_to_download.txt
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-0.20-mapreduce-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-client-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-conf-pseudo-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-hdfs-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm
http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/RPMS/x86_64/hadoop-hdfs-datanode-2.6.0%2Bcdh5.15.1%2B2822-1.cdh5.15.1.p0.4.el6.x86_64.rpm
...
...
...
Bash Run Script
links="`cat links_to_download.txt | xargs`"
for link in $links
do
echo "-> $link"
wget --http-user=nitin --http-password=XXXxxx --tries=2 -o=downloadlinks.log -r $link
RC=$?
if [[ "$RC" -ne "0" ]]; then
echo "[failed] - $RC"
else
echo "Done!"
fi
done
Which I will then install manually using yum install against local paths..
Is there a cleaner way to do this directly within the yum command ?
|
yum (a python script) is written to honor proxies; the code is in urllib.py in the getproxies_environment function:
Scan the environment for variables named _proxy;
this seems to be the standard convention. In order to prefer lowercase
variables, we process the environment in two passes, first matches any
and second matches only lower case proxies.
Since your repositories are HTTP (and not HTTPS), either set the variable http_proxy and export it before calling yum:
export http_proxy=http://username:[email protected]
or -- less flexible, since it would hard-code your password -- configure /etc/yum.conf with:
proxy=http://proxy.example.com:3128
proxy_username=yum-user
proxy_password=qwerty
| yum install fails with 401 Authorization required [closed] |
1,577,654,170,000 |
When I see the official documentation of ipfw or the man pages it seems that it is sometimes incomplete. Specifically, there are a lot of options like,
firewall_myservices
firewall_allowservices
etc., which can be found in many online guides but not in the docs. They're even discussed in the lists.
So I would like to understand if these are unofficial or undocumented options, and if they might be removed at some point in the future since they're not formally documented. More importantly, is there a single comprehensive documentation source for ipfw, short of grokking the source code?
|
So it seems that the options which are left out in the official docs are actually easily found in /etc/rc.firewall, which also happens to have the relevant explanations in the comments.
| Incomplete documentation for FreeBSD ipfw |
1,577,654,170,000 |
I tried to block all ports except 22(ssh), 80(http), 443(https). My current INPUT rules are these.
> iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:https
ACCEPT tcp -- anywhere anywhere tcp dpt:http
DROP all -- anywhere anywhere
it should accept http and https port and then block everything else. but It's blocking everything. for example when I try to visit facebook which uses port 80 & 443, it doesn't work. I can't visit facebook. what should I do now?
I also tried like this. Allowed mentioned ports and made the policy DROP, though I'm not sure. the same happens.
> iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:https
ACCEPT tcp -- anywhere anywhere tcp dpt:http
|
The policy rules that you've created will allow outside hosts to connect to your TCP ports 22, 80 and 443, but not allow any other traffic, including your own! If you really want to prevent this host from accessing anything other than these three ports, and don't want outside hosts to access yours at all, you can put the rules on your OUTPUT rule chain instead of your INPUT one and then have a CONNTRACK rule on your input chain to prevent connections that you didn't initiate:
-P INPUT DROP
-P OUTPUT DROP
-A INPUT -i lo -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -m udp -p udp --sport 53 -j ACCEPT
-A OUTPUT -i lo -j ACCEPT
-A OUTPUT -m tcp -p tcp --dport 22 -j ACCEPT
-A OUTPUT -m tcp -p tcp --dport 53 -j ACCEPT
-A OUTPUT -m udp -p udp --dport 53 -j ACCEPT
-A OUTPUT -m tcp -p tcp --dport 80 -j ACCEPT
-A OUTPUT -m tcp -p tcp --dport 443 -j ACCEPT
I usually allow the loopback adapter to work normally as some internal programs may need it; as well, I would allow DNS traffic, or else you won't be able to resolve domain names.
| Iptables - facing problems to allow specific ports and block others |
1,577,654,170,000 |
I've installed CSF-LFD as described here. in /etc/csf/csf.conf You have these two code blocks:
# Allow incoming TCP ports
TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,2077,2078,2079,2080,2082,2083,2086,2087,2095,2096"
# Allow outgoing TCP ports
TCP_OUT = "20,21,22,25,37,43,53,80,110,113,443,587,873,993,995,2086,2087,2089,2703"
I need both port groups to be changed just to "22, 80, 443, 9000" to make sure my Nginx server environment allows incoming data only from these ports.
What's the best, safest way to do that with sed?
I think that this is a good way:
sed -i 's/^TCP_IN = .*/TCP_IN = "22, 80, 443, 9000"/' /etc/csf/csf.conf
sed -i 's/^TCP_OUT = .*/TCP_OUT = "22, 80, 443, 9000"/' /etc/csf/csf.conf
Yet, given csf.conf is a huge file and might have huge potential for changes, there might be a tiny better way.
|
It can be done is one pass with sed:
sed -Ei 's/^(TCP_(IN|OUT) = ).*/\1"22, 80, 443, 9000"/' /etc/csf/csf.conf
(IN|OUT) - regex alternation group, matches either IN or OUT substring
\1 - backreference, references the 1st captured group (...)
| Change CSF-LFD ports safely with sed |
1,577,654,170,000 |
The guide recommends the Gufw firewall GUI.
I installed it by apt
gufw/oldstable,oldstable,now 12.10.0-1 all [installed]
graphical user interface for ufw
Typing ẁindow key + gufw, I cannot see the application.
Only access is through terminal by gufw which is not enough.
I am thinking why so + how to fix the issue because I am systematically using too little firewall in Linux.
Installation and testing the packages installed
Studying the package masi@masi:$ apt search gufw
Sorting... Done
Full Text Search... Done
gufw/oldstable,oldstable,now 12.10.0-1 all [installed]
graphical user interface for ufw
Installation by method apt install gufw
Output of apt show -a gufw where I am thinking about two packages (17.04 and 12.10) so something conflicting in my system - for some reason gufw in terminal starts gufw 12.10
Package: gufw
Source: gui-ufw
Version: 17.04.1-1.1
Installed-Size: 3,376 kB
Maintainer: Python Applications Packaging Team <[email protected]>
Depends: python3:any (>= 3.3.2-2~), ufw (>= 0.34~rc), gir1.2-gtk-3.0, policykit-1, gir1.2-webkit2-4.0, python3-gi, net-tools
Homepage: http://gufw.org/
Tag: admin::configuring, implemented-in::python, interface::graphical,
interface::x11, network::firewall, role::program, scope::utility,
security::firewall, uitoolkit::gtk, use::configuring, x11::application
Section: admin
Priority: optional
Download-Size: 842 kB
APT-Sources: http://ftp.fr.debian.org/debian/ unstable/main amd64 Packages
Package: gufw
Source: gui-ufw
Version: 12.10.0-1
Installed-Size: 1,328 kB
Maintainer: Devid Antonio Filoni <[email protected]>
Depends: python (>= 2.6.6-7~), ufw (>= 0.31.1), gir1.2-gtk-3.0, gir1.2-polkit-1.0, notify-osd | notification-daemon, policykit-1, python-dbus, python-gobject, gnome-icon-theme-symbolic
Homepage: https://launchpad.net/gui-ufw
Tag: admin::configuring, implemented-in::python, interface::x11,
network::firewall, role::program, scope::utility, security::firewall,
uitoolkit::gtk, use::configuring, x11::application
Section: admin
Priority: optional
Download-Size: 261 kB
APT-Manual-Installed: yes
APT-Sources: http://ftp.fi.debian.org/debian/ jessie/main amd64 Packages
Output of apt-cache policy gufw
gufw:
Installed: 12.10.0-1
Candidate: 12.10.0-1
Version table:
17.04.1-1.1 0
200 http://ftp.fr.debian.org/debian/ unstable/main amd64 Packages
*** 12.10.0-1 0
500 http://ftp.fi.debian.org/debian/ jessie/main amd64 Packages
500 http://httpredir.debian.org/debian/ jessie/main amd64 Packages
100 /var/lib/dpkg/status
Output of dpkg -l gufw
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===============================-====================-====================-====================================================================
ii gufw 12.10.0-1 all graphical user interface for ufw
I do the following and get sudo apt -t unstable install gufw
[sudo] password for masi:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
gsettings-desktop-schemas : Breaks: gnome-settings-daemon (< 3.19.92) but 3.14.2-3+deb8u1 is to be installed
Breaks: mutter (< 3.19.92) but 3.14.4-1~deb8u1 is to be installed
gstreamer1.0-plugins-base : Breaks: gstreamer1.0-plugins-bad (< 1.11.90) but 1.4.4-2.1+deb8u2 is to be installed
libgstreamer-plugins-base1.0-0 : Breaks: gstreamer1.0-plugins-bad (< 1.7.1) but 1.4.4-2.1+deb8u2 is to be installed
libgstreamer1.0-0 : Breaks: gstreamer1.0-plugins-bad (< 1.11.1) but 1.4.4-2.1+deb8u2 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
OS: Debian 8.7
Related bug: gufw: desktop entry doesn't show up in desktop environments
|
Debian Stretch was released a couple of weeks ago. Upgrading your entire system to that would seem like the easiest solution to your conundrum.
The bug was fixed in the version in Debian Stretch, while the old stable release Jessie was still stuck on a version from almost five years ago.
| Why Linux firewall GUI Gufw not in Debian window-key search? |
1,577,654,170,000 |
A Raspberry Pi is located behind a hardware firewall which is configured to block all outgoing communication to any IP except my server (all ports are allowed) and to block all incoming communication except the response requested by the Pi (obviously from my server). I can access the Pi from my server by tunneling within a SSH connection initiated by the Pi to my server. The firewall cannot be reconfigured.
RaspPi ---F/W---> MyServer <---Internet---> Repositories
How can I update the Pi as it cannot communicate directly to the repository URLs?
sudo apt-get -y update
|
2 and a half solutions - Do a ssh tunnel or set up a mirror or rather proxy connections to the mirror for the pi
Use a ssh tunnel.
From the pi, start a screen session or something and connect to your remote server via ssh with some arguments
ssh -L8000:hostname.of.apt.repo:80 user@remotebox
Then point your /etc/apt/sources.list entries to something like http://localhost:8000/raspbian - mine looks like
deb http://archive.raspbian.org/raspbian wheezy main contrib non-free
so I'd change it to
deb http://localhost:8000/raspbian wheezy main contrib non-free
And my ssh command would be
ssh -L8000:archive.raspbian.org:80 user@remotebox
Then run your normal apt-get update && apt-get dist-upgrade or whatever you want to do
Turn your box into the repository
Well, you probably don't want to mirror gigs of files for just one machine, so consider setting up a proxy (with authentication) and setting it to be used in your apt.conf file on the pi.
| Access repository where direct access to the repository's URL is blocked |
1,577,654,170,000 |
Closing ports except 22 and 443. This dramatically slows down the nmap scans:
-A INPUT -i eth0 -p tcp -m multiport --dports 22,443 -j ACCEPT
-A INPUT -i eth0 -p tcp -j REJECT --reject-with icmp-port-unreachable
If I remove the REJECT rule, nmap is fast.
So how to make other ports look like closed ports without slowing down the nmap?
|
It's the 'tcp-reset' reject type that does what the OS normally does with the closed ports:
-A INPUT -i ens3 -p tcp -j REJECT --reject-with tcp-reset
| Why REJECT slows nmap? |
1,577,654,170,000 |
SITUATION:
I recently found the following shell script that works with iptables to block all internet access to/from the linux OS, except for terminals opened that were in a group called internet:
CODE:
This might sound complicated, but it's simple. First, create the
"internet" group like so:
sudo groupadd internet
Then, save this into a script:
#!/bin/sh
# Firewall apps - only allow apps run from "internet" group to run
# clear previous rules
sudo iptables -F
# accept packets for internet group
sudo iptables -A OUTPUT -p tcp -m owner --gid-owner internet -j ACCEPT
# also allow local connections
sudo iptables -A OUTPUT -p tcp -d 127.0.0.1 -j ACCEPT
sudo iptables -A OUTPUT -p tcp -d 192.168.0.1/24 -j ACCEPT
# reject packets for other users
sudo iptables -A OUTPUT -p tcp -j REJECT
# open a shell with internet access
sudo -g internet -s
source: https://plus.google.com/+TobyKurien/posts/YZhZJCZmGgm
QUESTION:
Is the following interpretation of the events taking place correct?
sudo groupadd internet A group called internet is created
sudo iptables -F All current rules in iptables are cleared
sudo iptables -A OUTPUT -p tcp -m owner --gid-owner internet -j ACCEPT
I'm having trouble with this one... -A OUTPUT tells the terminal to append/add a rule, then according to the documentation -p is "The protocol of the rule or of the packet to check", so -p tcp seems to be placing a rule that only reflects the tcp protocol, but what If I want to watch a stream on youtube/twitch? Does udp need to be included, and if so, how would I include it?
Then there is the -m (for match). I read the documentation and I am not sure what it does. Right now, I have no idea what -m owner --gid-owner internet -j means. From the comment # accept packets for internet group I understand what the code does, but I want to understand what each element is doing in order to get to that conclusion.
|
Your interpretation is correct.
If you want the whole thing to also apply to UDP packets, you have to add the same set of rules once again, but with -p udp instead of -p tcp. Or just leave out this option and have the rules apply to all packets (though there could be some gotchas with ICMP packets, so it's probably safer to just add both kinds of rules). However, you'll need TCP in the first place to access e.g. Youtube, so even if streaming from Youtube used UDP, you wouldn't be able to watch a stream, because you'll never get this far.
The option -m selects which kind of match to use. You can match on lots of different criteria, and there's even extensions to iptables (man iptables-extensions) with even matching modules. Here, -m owner selects match by ownership of packets, and --gid-owner specifies to match group ownership. So both options together mean "this rule applies only to packets that are send from someone in group internet".
The option -j (originally "jump") specifies what to do when the rule matches. You can jump to a different chain, or you can ACCEPT (stop processing rules and send this packet), or you can REJECT (stop processing rules and ignore this packet).
The next two rules allow packets (ACCEPT) for special destinations (-d), no matter what group the sending application is in, and the last rule drops all packets (REJECT) that didn't match the previous rules. So it's this last rule that does the actual blocking.
There are plenty of tutorials for iptables on the internet, google a bit and pick one you like if you want to learn more details. Some random links that I found useful in the past:
http://developer.gauner.org/doc/iptables/images/nfk-traversal.png
http://www.netfilter.org/documentation/HOWTO/packet-filtering-HOWTO-7.html#ss7.2
http://www.netfilter.org/documentation/HOWTO/netfilter-extensions-HOWTO.html
http://www.iptables.info/en/iptables-targets-and-jumps.html
https://www.frozentux.net/documents/iptables-tutorial/
https://www.frozentux.net/iptables-tutorial/iptables-tutorial.html
| Understanding an iptables shell script |
1,577,654,170,000 |
I am new to iptables and am confused on how I am supposed to set this up. It looks like I have 2 ethernet cards but I have 4 IP addresses. No prob there. In my network/interfaces, it looks like they are all on enp2s0f0. Can I just change 2 of them to be on interface enp2s0f1 assuming that the network comming into the server is the same as enp2s0f0?
If in iptables you specify eth0 (in my case enp2s0f0) then how am I supposed to make rules for each IP?
What I tried to do is specify the iface in network/interfaces as shown below however iptables shows the destination as "anywhere" when I specifically set it to enp2s0f0:0 and enp2s0f0
iptables -A INPUT -i enp2s0f0 -p tcp --dports 80,443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o enp2s0f0 -p tcp --sports 80,443 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i enp2s0f0:0 -p tcp --dports 80,443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o enp2s0f0:0 -p tcp --sports 80,443 -m state --state ESTABLISHED -j ACCEPT
Here is my ouput showing my interfaces...
$ls /sys/class/net
enp2s0f0 enp2s0f1 lo
$cat /etc/network/interfaces
auto lo
iface lo inet loopback
# The primary network interface
auto enp2s0f0
iface enp2s0f0 inet static
address xx.xx.xx.76
netmask 255.255.255.0
network xx.xx.xx.0
broadcast xx.xx.xx.255
gateway xx.xx.xx.1
auto enp2s0f0:0
iface enp2s0f0:0 inet static
address xx.xx.xx.77
netmask 255.255.255.0
network xx.xx.xx.0
broadcast xx.xx.xx.255
auto enp2s0f0:1
iface enp2s0f0:1 inet static
address xx.xx.xx.78
netmask 255.255.255.0
network xx.xx.xx.0
broadcast xx.xx.xx.255
auto enp2s0f0:2
iface enp2s0f0:2 inet static
address xx.xx.xx.79
netmask 255.255.255.0
network xx.xx.xx.0
broadcast xx.xx.xx.255
l
|
I quote some lines from man iptables:
[!] -p, --protocol protocol
The protocol of the rule or of the packet to check.
[!] -s, --source address[/mask][,...]
Source specification. Address can be either a network name, a hostname,
a net‐work IP address (with /mask), or a plain IP address.
[!] -d, --destination address[/mask][,...]
Destination specification.
I consider the case you have two interfaces with two static IP each, since you can do that.
So, if you want to match specific IPs, you can rearrange your rules:
iptables -A INPUT -i enp2s0f0 -p tcp -s 0.0.0.0 -d <IP> --dports 80,443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o enp2s0f0 -p tcp -s <IP> -d 0.0.0.0 --sports 80,443 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i enp2s0f1 -p tcp -s 0.0.0.0 -d <IP> --dports 80,443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o enp2s0f1 -p tcp -s <IP> -d 0.0.0.0 --sports 80,443 -m state --state ESTABLISHED -j ACCEPT
Of course you have to change <IP> with your machine IP(s). If you want to allow connections only from/to certain IPs change 0.0.0.0 too.
| How to set different rules to multiple IPs on the same interface? |
1,577,654,170,000 |
I have some devices that don't have firewall neither can't have, it's like an arduino, more specifically its a esp8266 with "ESP-Easy" Firmware.
And what i want/need is to only a certain computer be able to access it. like this:
1# ESP8266 board with ip 192.168.1.102
2# Computer with ip 192.168.1.100
3# Any other Device with a unknown IP address
2# is abble to communicate with 1# and vice versa
3# is able to commumnicate with 2# but NOT with 1#
How can i archieve that if 1# have no firewall. I thought how about my router firewall that have OpenWrt installed... but how?
What's type of rule i need or what rules i need
|
There is no secure solution to this if the devices are on the same LAN. Nodes on the same network talk directly to each other, there is no way to divert the traffic via an firewall. You will have to put the computer and the board on a separate LAN, with a firewall between the LANs. A cheap, but insecure, solution is to add a second IP address to the network interface on the computer, say 10.0.0.1/30, and give the board address 10.0.0.2/30. This way they are on the same physical network, but are using a different subnet.
| How prevent access to a device (192.168.1.102) from others devices than the one I allow (192.168.1.100) if the 192.168.1.102 don't have firewall |
1,577,654,170,000 |
Is it really necessary to run UFW behind my Gateway Router which already has Firewall/Port rules?
In this example, I am discussing running UFW on an Internet Accessible (Linux) Server that is behind a Natted Firewall Gateway Router.
Please be specific, don't just say yes because there are hackers out there! (Though that is valid answer)
Is it just for internal protection? If so, I know I can trust my LAN, can I not run UFW?
|
Ultimately this is a security question more than a unix/linux question.
Technically the answer is no, it is not necessary to run it for things to work right (depending on what else you're running).
I don't run host firewalls on my network at home because I have my modem/router/accesspoint set up such that there are no inbound connections allowed, and like you I 'trust' my home lan.
However, this is my home lan. I have very little interesting data on it and nothing to attract hackers, and mostly the sort of defenses that keep out drivebys.
The next threat then is malicious code delivered via your web browser. This really means that you can't trust your home network. In this scenario someone hijacks a web server (cross sight scripting, whatever) and you wind up with some sort of bot on your machine that then scans your network and replicates. There was a government facility with a classified "Secret" network (meaning the data on it was classified secret, not the network itself) that had an infestation that they were having serious trouble getting rid of because whatever was on their machines was spreading as fast as they could reimage machines. This, however, was almost all Windows machines on Active Directory with the mono-culture and security problems that implies[1].
Maybe it's a problem for you, maybe it isn't. That's your evaluation to make.
Ultimately on a home network with very little to no inbound ports open, minimal network services running and otherwise good security practices host based firewalls aren't going provide a significant gain in security.
However, in a business with any sort of PII then you go that extra mile.
THAT SAID. We all should probably be running host based firewalls. We should know what network activity the computer is initiating on our behalf and taking care of it.
But busy and distrac...
| Is UFW behind a firewall(ed) gateway router necessary |
1,577,654,170,000 |
I need to install some iptable ruels to block traffic that originates from a certain country, I found this script example on http://www.cyberciti.biz/faq/block-entier-country-using-iptables/ it works great on another host I have but on this one (an embedded box) I get:
./iptable_rules.sh
modprobe: module ip_tables not found in modules.dep
iptables v1.4.16.3: can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
Now upgrading the kernel due to the nature of the device, is not an option. Does anyone know a way I can get around this? This system running on kernel 3.2.34
|
You should be able to re-compile it using something to the similar commands.
make KERNEL_DIR=/usr/src/linux
make install KERNEL_DIR=/usr/src/linux
make dep
make bzImage
make
make install
make modules
Source: iptables: Table does not exist (do you need to insmod?)
| iptables - why do I get "Table does not exist (do you need to insmod?)" |
1,577,654,170,000 |
How can I define separate roles for users and administrator in OpenVPN running on CentOS 7 server? Specifically, the users must only be allowed to https, while the administrator must be allowed to both https and ssh.
PROGRESS SO FAR:
In translating the instructions from the link suggested by @garethTheRed, I have defined the following steps. I have also completed steps one, two, and three. But I do not know how to complete step four. Can someone please show how to translate STEP FOUR into firewalld from iptables, and also confirm the other steps?
Step One (COMPLETED): Create a virtual IP address map according to user class:
Class Virtual IP range Allowed Services
employees 10.8.0.0/24 https
administrator 10.8.1.0/24 ssh, https
Step Two (COMPLETED): In /etc/openvpn/server.conf,
define the Employee IP address pool:
server 10.8.0.0 255.255.255.0
Add a route for the System Administrator IP range:
route 10.8.1.0 255.255.255.0
Specify client configuration directory to assign a fixed IP forAdministrator:
client-config-dir ccd
Step Three (COMPLETED): In a new directory /etc/openvpn/ccd and new config file /etc/openvpn/ccd/sysadmin:
Define the fixed IP address for the Administrator VPN client:
mkdir ccd
cd ccd
nano sysadmin1
type the following into /etc/openvpn/ccd/sysadmin1:
ifconfig-push 10.8.1.1 10.8.1.2
Step Four (HOW DO I DO THIS IN FIREWALLD SO THAT USERS CAN ONLY https AND SO THAT ADMINISTRATOR CAN ssh AND https?):
First, define a static unit number for our tun interface:
dev tun0 //where does this go?
Establish firewall rules for the employees and administrator (convert these to firewalld):
# Employee rule // MUST ONLY BE ALLOWED TO https
iptables -A FORWARD -i tun0 -s 10.8.0.0/24 -d 10.66.4.4 -j ACCEPT
# Sysadmin rule //MUST BE ALLOWED TO ssh AND https
iptables -A FORWARD -i tun0 -s 10.8.1.0/24 -d 10.66.4.0/24 -j ACCEPT
Note: When I type firewall-cmd --list-all, the sum total of the entire firewalld configuration so far is defined as follows:
public (default, active)
interfaces: enp3s0
sources:
services: dhcpv6-client openvpn smtp
ports:
masquerade: yes
forward-ports:
icmp-blocks:
rich rules:
I would like to change the firewall configuration in any way required to provide optimal security for this use case.
How do I modify the above to get this working?
EDIT:
After reading @garethTheRed's helpful answer, I have three questions/observations:
1.) There is no `tun` device on the firewall, but yet I am able
to connect to the VPN from the client with
`openvpn --config /path/to/client.ovpn` with the firewall
configured only as shown by the results of `firewall-cmd --list-all`.
So why is it necessary to define a `tun` device in the firewall?
2.) `ip addr` shows that I was logged in as 10.8.0.6. How can I
force being logged in as a fixed address, such as 10.8.1.1 defined
in Step Three above?
3.) What privileges/access does a user really have when they log in to the
server via OpenVPN when the firewall is configured as shown in the
results of `firewall-cmd --list-all` above? Are they be able to do
anything other than https without a password anyway? ssh would
require knowledge of both a password and a username.
EDIT#2
In the internal zone defined in @garethTheRed's very helpful answer, it would seem that the users of the internal zone have access to the following services dhcpv6-client, ipp-client, mdns, samba-client, and ssh. The use case in this posting would also include https.
Therefore, it would seem that the solution to this posting would involve:
1.) setting up rules blocking the `10.8.0.0/24` ip range from
`dhcpv6-client`, `ipp-client`, `mdns`, `samba-client`, and `ssh`,
while allowing access to `https`.
2.) retaining access by the `10.8.1.0/24` ip range to all services
defined in the internal zone.
3.) creating and installing separate client certificates for the
two classes of users (administrator and user)? Each class,
and therefore each certificate, must have a Canonical Name (CN)
that matches the names of config files added to `/etc/openvpn/ccd`.
Openvpn should then use the config file whose name matches the CN.
This config file should be set to configure the network address
that will be allocated to the clients in that class
@garethTheRed's words are used here in #3.
But are these 3 things what are still required to complete this requirement? And how do I accomplish these 3 things?
|
You could modify the zone and add a Rich Rule which blocks all ssh traffic other than from a certain range - the Employee subnet.
Find which zone your tun interface is in by listing all zones:
firewall-cmd --list-all-zones | less
In the output you should see something similar to:
internal (active)
interfaces: tun0
sources:
services: dhcpv6-client ipp-client mdns samba-client ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
You may find that the tun device (tun0 in the example above) is in the same zone as your ethernet adapter. While this will work, it will be easier to manage if you separate them.
It would be wise to remove the service that you don't need from the internal zone - in your case, remove all but ssh and also add http:
firewall-cmd --zone=internal --permanent --add-service=http
firewall-cmd --zone=internal --permanent --remove-service=dhcpv6-client
Repeat the last command with the other services you want to remove. Make sure you don't remove ssh! While you're at it, remove redundant services from your external zone too.
Copy the zone definition file from the zone where the tun interface is located to /etc/firewalld/zones. For example, if the tun device is in the Internal zone:
sudo cp /usr/lib/firewalld/zones/internal.xml /etc/firewalld/zones
Edit the copied file and add the following just before the closing </zone>:
<rule family="ipv4">
<source invert="True" address="10.8.0.0"/>
<service name="ssh"/>
<reject/>
</rule>
Finally, run firewall-cmd --reload to apply the rule.
Warning: You may lock yourself out if this doesn't work :-o
Alternative Options:
Another, simpler option, would be to configure sshd to only accept connections from a given network address - 10.8.0.0.
An even simpler option would be to abandon the VPN altogether and only use the firewall. If (and only if) your employees (or your external router) have a static IP address then simply configure Rich Rules to allow only their IP address or network address to reach the ssh service while rejecting all other IP addresses.
| multiple user-types/access-rules for OpenVPN on CentOS 7 and firewalld |
1,577,654,170,000 |
I'm trying to secure my internet browsing. I just reinstalled Xubuntu 14.04 and GUFW firewall. I have 8 UDP ports open. I don't understand why. The software I currently have open are Firefox, GUFW, Mousepad, Ubuntu Software Center, Software Updater and Terminal. Would any of these correspond with the open software? When I installed GUFW its introduction said it installs with no open ports as well as Ubuntu. The applications related to the open ports are avahi-daemon, dhclient, and cups-browsed. I'd rather close them if they're not needed.
Instructions on closing them via GUFW or Terminal would be appreciated as I am a novice.
I can attach a screen print if needed.
|
avahi-daemon
Avahi is a low-level service discovery mechanism. It tends to be used by all kinds of random things, so there's no way I can tell you exactly who is using it, and for what.
Short of pulling out the packet sniffer and going hunting, your choices are basically to just live with it or disable the whole service and see what breaks.
dhclient
This is the DHCP client. It needs to receive UDP packets on port 68. If your computer uses DHCP to configure its networking, you need to keep this open.
If you don't use DHCP on that computer, you can simply remove dhclient entirely.
cups-browsed
CUPS is the printing subsystem of your Linux distro. You can remove this service, but that will mean your GUI won't be able to find new printers when they appear on the network. You'll have to go back to the bad old days of manually typing in IP addresses.
(Unless it's a Bonjour printer, in which case it will be picked up by Avahi. Printer discovery is just one of the many things Avahi can do, however. Don't get the idea that these two services are mutually redudant. Avahi's wide footprint just happens to overlap CUPS a bit in this area.)
I wouldn't worry about this service. It isn't tied into anything really sensitive.
| Open UDP Ports; Can I Close Them? |
1,577,654,170,000 |
I have a Raspberry Pi running Linux (Raspbian) which is connected to my corporate Internet over an Ethernet cable. The RPi also has a wifi adaptor plugged into a USB port. I've been following along the with Ada Fruit's Raspberry Pi Access Point Tutorial, but there is a snag.
I only want to allow connections from the wifi USB adaptor to reach services running on the RPi. I don't want them to be allowed to connect to the corporate network in any way. The RPi is running a service which should be available both over the corporate intranet and over the wifi connection. The RPi must not route any connection between the wifi network and the corporate intranet.
My question is, what part of the tutorial should I follow, and should I not follow to make this setup work?
|
The section you should ignore is the Configure Network Address Translation section. In fact if you want to guarantee that wireless clients can't go onto the Ethernet connection do the following:
Run sudo nano /etc/sysctl.conf. Scroll to the bottom and add net.ipv4.ip_forward=0
on a new line. Save the file. This will disable ip forwarding on boot up.
Run: sudo sh -c "echo 0 > /proc/sys/net/ipv4/ip_forward"
This will disable IP forwarding immediately (it should be disabled already). This will guarantee that there is no IP forwarding on your Pi.
If you want to go a little further, you can also disable it at the firewall, but adding the following iptables rules.
sudo iptables -A FORWARD -i wlan0 -o eth0 -j DENY
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Run sudo nano /etc/network/interfaces and add up iptables-restore < /etc/iptables.ipv4.nat to the very end. Save and close the file.
That should disable all traffic from wireless to the corporate network.
For more information about Linux networking options take a look here: https://www.kernel.org/doc/Documentation/sysctl/net.txt
| Allow wifi connections only to a local service, don't route to the wired ethernet |
1,577,654,170,000 |
I tried to curl popular websites e.g. curl google.com or curl google.com:80 and there is always a timeout error.
Some troubleshooting steps performed:
Able to curl localhost with response
Able to ping google.com with response
Tried change DNS to google DNS but to no avail
Tried wget and it does not work for external sites either
Questions:
May I know what is the default port that curl is using?
Is this related to Firewall blocking? As far as I know port 80 is open for
the server I am using.
What else can I do to further troubleshoot?
|
If this is a hosted webserver I would suspect that it's been configured in a classic webserver fashion. Meaning that it allows incoming connections on port 80 but for security they may have disallowed outgoing connections on port 80. I would guess this is the issue. curl and wget generally work out of the box with no issues. curl chooses a port based on the URI given (http will be 80, https 443, ftp 21, and so on); when no protocol is given as you are using it will use 80. To troubleshoot this just disable your firewall for a second (or edit the settings if you are worried about it being down for a few seconds).
Update:
May I know is there a easy way to confirm that port 80 (outgoing) is block?
I'd say that you've done this already. wget is especially hard to mess up. If it isn't working I'd say it is a safe bet. An even better way is to look at your firewall setup and confirm this to be the case.
Is there any security concern we need to take note for enabling port 80 (outgoing)?
Oh yes. It isn't that doing this makes you less secure; it is that by opening this it means that if someone does gain the ability to say, inject a little javascript code into your site DB, they could use your site to commit crimes which would be very difficult to trace back to them (because all indications of who the attacker is show you as the culprit). The only thing that could really clear your name are your own logs which aren't very convincing since you provided them to the court in the first place.
I don't think I have rights to disable the firewall, please advise what would be the settings that need to be edit? Is it configure the firewall to allow port 80 outgoing?
You may be right. I cannot really tell you the answer to this because you are clearly using some sort of hosted solution. iptables is the name of the most popular Linux firewall. You should see it listed in /etc/init.d if you have it installed. If not, you'll need to go to the website for your web host and find out how it should be managed.
| curl timeout troubleshooting |
1,577,654,170,000 |
I'm running a desktop computer, but one with high threat risk.
I've blocked all ports using a firewall except:
HTTP, HTTPS, DNS, one port for torrent client.
Do any common processes in distros like Ubuntu, Linux Mint, Debian use other ports that I need to allow?
|
In principle, modern firewalls are 'stateful'.
Meaning you don't need to allow anything from outside as it will find out itself which are the answers to requests that you have made and let them in automatically.
So you don't need incoming HTTP or HTTPS, etc. explicitely unless you're hosting a webserver.
However, if you have a port forwarding for your torrent client, you indeed need to allow that, because there is no outgoing connection asking for a reply but indeed a new connection coming in from outside in that case.
In practice it should look more or less like this for starters (look up an iptables tutorial for details):
Chain INPUT (policy DROP)
num target prot opt source destination
1 DROP all -- 0.0.0.0/0 0.0.0.0/0 state INVALID
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
Chain FORWARD (policy DROP)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
Might be useful to allow ssh port besides a torrent port, but then make sure your ssh password is secure or use keys.
| What ports are essential and should generally be allowed on a Linux system? |
1,577,654,170,000 |
I'm new in CentOS and I'm trying to create a little script in Python, something like:
$ python -m SimpleHTTPServer
If I try to access port 8000 in my web browser, I don't get access, however if I turn off the firewall with:
$ system-config-firewall-tui
I'm able to access the service.
I just need to access port 3343 and 8880 but I don't want to disable the firewall.
|
Try something like this:
$ iptables -A INPUT -p tcp --dport 3343 -j ACCEPT
$ iptables -A INPUT -p tcp --dport 8880 -j ACCEPT
| Open a port CentOS |
1,577,654,170,000 |
I´m having problems setting up network printing in Fedora 16. In the printer setup box it says FirewallD is not running and gives a list of protocols that need to be enabled. I cannot find a FirewallD but have gone into Firewall and enabled the protocols. There is obviously something I´m missing.
The printer is a Canon MP970 and is connected to a Windows machine.
Update: 4Nov12
Bought a new printer - same problem. This time I set it up properly as a network printer. Windows 7 and Ubuntu both find the printer and print fine. Fedora still complains FirewallD is not running.
The new printer is a Canon MG6250. I have installed the drivers from RPM packages.
|
Finally found the answer in the Ask Fedora forums. Someone there had the same problem and one of the responces said to enter system-config-printer into Terminal and configure the printer that way. I can now print!
| Network Printing in Fedora |
1,577,654,170,000 |
I configured a Debian Squeeze virtual machine in VMWare on my laptop. I configured it with a very restrictive set of firewall rules using Firestarter. I then uploaded a copy of its disk image to use as a virtual private server on the internet.
On the internet version, I rather rashly removed my firewall settings via the following command:
apt-get purge firestarter
I’ve since realised I want to restore the firewall rules to their old state, which is still on the original virtual machine on my laptop.
My question is: how can I copy the firewall settings from the virtual machine on my laptop to the one on the internet?
I tried copying /sbin/iptables from the original virtual machine to the new one, but that hasn’t had any effect (according to the output of iptables -L).
|
You can use iptables-save and iptables-restore, or you can once more install firestarter and use the config file from the old machine.
| How can I move firewall settings from one Debian Squeeze web server to another? |
1,577,654,170,000 |
I am feeling stupid. I have been searching for 3 hours with no success.
I installed Fedora 14 and tried to do yum install firestarter but the package was not found.
I also tried from a GUI and found nothing.
It is at fedoras repository?
Maybe I should configure the repository, but all I found are dated. Any help? Thank you.
|
Firestarter hasn't been in the fedora repository since Fedora 11. It's listed as a deprecated package on their wiki. It's recommended that you use system-config-firewall instead.
Do you have a particular reason for wanting to use firestarter? If you really want to install it you can try grabbing the source from sourceforge.
| I can't figure out how to install Firestarter Fedora |
1,577,654,170,000 |
I have an OpenWrt 10.03 router [ IP: 192.168.1.1 ], and it has a DHCP server pool: 192.168.1.0/24 - clients are using it through wireless/wired connection. Ok!
Here's the catch: I need to separate the users from each other.
How i need to do it: by IPTABLES rule [ /etc/firewall.user ]. Ok!
"Loud thinking": So i need a rule something like this [on the OpenWrt router]:
- DROP where SOURCE: 192.168.1.2-192.168.1.255 and DESTINATION is 192.168.1.2-192.168.1.255
The idea is this. Ok!
Questions!
- Will i lock out myself if i apply this firewall rule?
- Is this a secure method? [ is it easy to do this?: hello, i'm a client, and i say, my IP address is 192.168.1.1! - now it can sniff the unencrypted traffic! :( - because all the clients are in the same subnet! ]
- Are there any good methods to find/audit for duplicated IP addresses?
- Are the any good methods to find/audit for duplicated MAC addresses?
- Are there any good methods to do this IPTALBES rule on Layer2?:
$ wget -q "http://downloads.openwrt.org/backfire/10.03/ar71xx/packages/" -O - | grep -i ebtables
$
p.s.: The rule would be [is it on a good chain?]:
iptables -A FORWARD -m iprange --src-range 192.168.1.2-192.168.1.255 --dst-range 192.168.1.2-192.168.1.255 -j DROP
Thank you!
|
If you want to separate wireless and wired users why not match the interfaces?
Assuming ppp0 is facing the internet, eth0 is your local LAN and wlan0 is the wireless:
iptables -P FORWARD DROP # Drop everything except:
iptables -A FORWARD -m state --state RELATED,ESTABLISHED # Accept already accepted connections
iptables -A FORWARD -i eth0 -o ppp0 -j ACCEPT # Accept outgoing connections from local LAN
iptables -A FORWARD -i wlan0 -o ppp0 -j ACCEPT # Accept outgonig connnections from wlan
If you use this:
nothing can be connected from the internet
wireless users can only connect to the internet
wired users can only connect to the internet
you can enforce separate IP ranges if you add the --src-range
If your DHCP server is running on the OpenWrt device then the FORWARD chain will not affect that in any way. To allow the DHCP server use
iptables -P INPUT DROP # Drop everything except:
iptables -A INPUT -m state --state RELATED,ESTABLISHED # Accept already accepted connections
iptables -A INPUT ! -i ppp0 -p tcp --dport 22 -j ACCEPT # Don't forget SSH
iptables -A INPUT ! -i ppp0 -p udp --sport 68 --dport 67 # Accept DHCP requests from any local network
I generally allow everything in OUTPUT except a few types of ICMP and spam. But you might prefer the safer default DROP so here is the specific rule:
iptables -P OUTPUT DROP # Drop everything except:
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT ! -o ppp0 -p udp --sport 67 --dport 68 -j ACCEPT # Allow DHCP to the local network
It makes more sense on a router which is not supposed to connect to everything.
I would advise against MAC filtering in my experience it adds no security only inconvinience. But if you want to see:
iptables -m mac --help
Logging MAC addresses could be useful but they are easily forged. Just add -j LOG or -j NFLOG before the ACCEPT rule with the same matching rules.
Since you are configuring a computer which is only accessible from the network you should be very careful not to lock yourself out. You can't just walk to it and delete the rules manually. In particular typing iptables -P INPUT DROP with an empty INPUT chain will kill your SSH session. I recommend using the iptables-save and iptables-restore and writing the rules in a config file. It also helps if you can test the rules on a computer with a keyboard and monitor before trying it on the router.
| IPTABLES rule for separating users |
1,577,654,170,000 |
I've set up a rule to match multicast packets as follows:
add rule filter_4 new_out_4 meta pkttype multicast goto multicast_out_4
filter_4 is IPv4 table, new_out4 is output chain and multicast_out_4 is a chain to handle multicast only traffic.
Here is a more complete picture of the IPv4 table excluding non-relevant portion:
#!/usr/sbin/nft -f
add table filter_4
add chain filter_4 output {
# filter = 0
type filter hook output priority filter; policy drop;
}
add chain filter_4 multicast_out_4 {
comment "Output multicast IPV4 traffic"
}
add chain filter_4 new_out_4 {
comment "New output IPv4 traffic"
}
#
# Stateful filtering
#
# Established IPv4 traffic
add rule filter_4 input ct state established goto established_in_4
add rule filter_4 output ct state established goto established_out_4
# Related IPv4 traffic
add rule filter_4 input ct state related goto related_in_4
add rule filter_4 output ct state related goto related_out_4
# New IPv4 traffic ( PACKET IS MATCHED HERE )
add rule filter_4 input ct state new goto new_in_4
add rule filter_4 output ct state new goto new_out_4
# Invalid IPv4 traffic
add rule filter_4 input ct state invalid log prefix "drop invalid_filter_in_4: " counter name invalid_filter_count_4 drop
add rule filter_4 output ct state invalid log prefix "drop invalid_filter_out_4: " counter name invalid_filter_count_4 drop
# Untracked IPv4 traffic
add rule filter_4 input ct state untracked log prefix "drop untracked_filter_in_4: " counter name untracked_filter_count_4 drop
add rule filter_4 output ct state untracked log prefix "drop untracked_filter_out_4: " counter name untracked_filter_count_4 drop
In the above setup new output traffic including multicast is matched by rule add rule filter_4 output ct state new goto new_out_4
Here is new_out_4 chain with only the relevant (non working) multicast rule that doesn't work:
# Multicast IPv4 traffic ( THIS RULE DOES NOT WORK, SEE LOG OUTPUT BELOW)
add rule filter_4 new_out_4 meta pkttype multicast goto multicast_out_4
#
# Default chain action ( MULTICAST PACKET IS DROPPED HERE )
#
add rule filter_4 new_out_4 log prefix "drop new_out_4: " counter name new_out_filter_count_4 drop
Here is what the log says about dropped multicast packet:
drop new_out_4: IN= OUT=eth0 SRC=192.168.1.100 DST=224.0.0.251 LEN=163 TOS=0x00 PREC=0x00 TTL=255 ID=27018 DF PROTO=UDP SPT=5353 DPT=5353 LEN=143
The packet that is dropped was sent to destination address 224.0.0.251, this is multicast address, it was supposed to be matched by multicast rule in new_out_4 chain and was supposed to be processed by multicast_out_4 chain but was not.
Instead the packet was not matched and was dropped by default drop rule in new_out_4 chain above, see comment (Default chain action).
Obviously this means that the multicast rule does not work.
Why multicast rule doesn't work?
Expected:
meta pkttype multicast matches destination address 224.0.0.251
EDIT:
System info:
Kernel: 6.5.0-0.deb12.4-amd64
had the same problem with earlier kernel 6.1
nftables: v1.0.6 (Lester Gooch #5)
|
Having reproduced (and completed missing parts for) the setup with a few additional entries such as:
nft insert rule filter_4 new_out_4 counter meta pkttype host counter
indeed the property meta pkttype for this skbuff is host rather than the expected multicast for an outgoing multicast packet. Note that when this keyword was introduced, it was about input, not output:
src: Add support for pkttype in meta expresion
If you want to match the pkttype field of the skbuff, you have to use
the following syntax:
nft add rule ip filter input meta pkttype PACKET_TYPE
where PACKET_TYPE can be: unicast, broadcast and multicast.
Actually the direct equivalent with iptables is the pkttype match module:
pkttype
This module matches the link-layer packet type.
[!] --pkt-type {unicast|broadcast|multicast}
# iptables-translate -A OUTPUT -m pkttype --pkt-type multicast
nft 'add rule ip filter OUTPUT pkttype multicast counter'
Putting all this together, when an outgoing IP (routing: layer 3) packet is created, it has not yet reached its layer 2 (link-layer) so its skbuff doesn't reflect what it might become, if it's even intended to later.
What should actually be tested is the IP address property with regard to the routing stack, rather than the packet property wih regard to Ethernet. iptables provides for this the addrtype match module:
addrtype
This module matches packets based on their address type. [...]
Its translation hints what should actually be used: the fib expression:
# iptables-translate -A OUTPUT -m addrtype --dst-type MULTICAST
nft 'add rule ip filter OUTPUT fib daddr type multicast counter'
FIB EXPRESSIONS
fib {saddr | daddr | mark | iif | oif} [. ...] {oif | oifname | type}
A fib expression queries the fib (forwarding information base) to
obtain information such as the output interface index a particular
address would use. The input is a tuple of elements that is used as
input to the fib lookup functions.
There's no direct example for multicast. The nearest example is a more complex one about dropping a pacjet not intended for an address on the incoming interface, where multicast is in the 3 exceptions:
# drop packets to address not configured on incoming interface
filter prerouting fib daddr . iif type != { local, broadcast, multicast } drop
So just replace wherever used in an output (or postrouting) hook:
meta pkttype multicast
with:
fib daddr type multicast
In an input (or prerouting) hook, while the skbuff property probably matches the IP property, to be consistent, it should also be replaced exactly the same, also with:
fib daddr type multicast
The test command below, used conjointly on an other host in the LAN (to test input) and on the host (to test output):
socat -d -d UDP4-DATAGRAM:224.0.0.251:5555,bind=:5555,ip-add-membership=224.0.0.251:eth0 -
will properly match fib daddr type multicast in input and output.
Important remark:
I believe above addressed the question, but note however that multicast cannot be properly tracked by Netfilter's conntrack, because it can't associate a reply using an other unicast source address to the multicast destination address of the initial query: they differ so it considers the reply to be an other (new) flow instead of associating them and considering such reply as part of the previous flow. So such kind of flow will never appear as ESTABLISHED state with conntrack or the conntrack -L command. The ruleset should be adapted for this: it can't rely only on ct state established,related kind of rules, but that's beyond the scope of this question.
| nftables - multicast packets not matched |
1,577,654,170,000 |
I have flowtable offloading working just perfect on my router. Sometimes I want to block some ongoing traffic, being handled via the flowtable. If I add a new blocking rule to the regular routing processing, it has no effect to the active offloaded connections. Therefore after I added some new rule, I would like to flush the hash of the flowtable to make it rebuilt again. But how? I have not found any way with nft command to emtpy the offloaded connections.
I could destroy the flowtable and re-create, but is there no nicer way for that?
|
Offloaded traffic is still associated with a conntrack entry with the property [OFFLOAD] (offloaded entries have a default 30s inactivity timeout and revert to non-offloaded conntrack entries without traffic seen for this time, until they get the chance (traffic) to be offloaded again). To remove the flowtable entry, remove the conntrack entry, using conntrack -D.
Update: this feature has been made available with this commit:
netfilter: ctnetlink: Support offloaded conntrack entry deletion
Currently, offloaded conntrack entries (flows) can only be deleted
after they are removed from offload, which is either by timeout, tcp
state change or tc ct rule deletion. This can cause issues for users
wishing to manually delete or flush existing entries.
and requires kernel 6.4 or a recent enough LTS 6.1.x (~ >= 6.1.32) where it has been backported with reference example in commit:
Example usage:
# Delete all offloaded (and non offloaded) conntrack entries
# whose source address is 1.2.3.4
$ conntrack -D -s 1.2.3.4
# Delete all entries
$ conntrack -F
Following LTS kernels also have the commit, make sure the a recent enough is in use: 4.19, 5.4, 5.10, 5.15.
On an older kernel, trying to delete such conntrack entry will return EBUSY (as can be seen with this error removed in the commit).
The simplest to remove all and only [OFFLOAD] entries is:
conntrack -D --status OFFLOAD
or for hardware offload (not tested) that would be:
conntrack -D --status HW_OFFLOAD
But this isn't completely reliable since a flow could have reverted to non-OFFLOAD status at the wrong time, so should better not be part of the removal filter. Using additional properties of the conntrack entries (as seen with conntrack -L ...) to remove such entry should be preferred, such as protocol, source address, port etc.
So a tool like fail2ban which would add an entry to a set blacklist working before the usual ESTABLISHED stateful rule might have to provide the 5-uple (to remove a single flow) or just the source address (to remove all related flows for this address). For example to block (original) source 192.0.2.11 currently (or not) with status OFFLOAD, in addition to updating a set used by a drop rule, one can run (with no special care about the OFFLOAD status):
conntrack -D -s 192.0.2.11
| How to flush the nft flowtable hash of active connections? |
1,577,654,170,000 |
I'm using nftables on a router running NixOS 22.11 (with the latest XanMod kernel patches and acpid as well as irqbalance enabled). The machine has 3 interfaces: enp4s0 which is connected to the internet and two local WiFi access points serving distinct IP LANs, wlp1s0 and wlp5s0.
My nftables configuration is the following: I just allow inbound DNS, DHCP and SSH traffic on the the local networks, and as allow outbound and forwarded traffic to the internet along with SNAT.
table ip filter {
chain conntrack {
ct state vmap { invalid : drop, established : accept, related : accept }
}
chain dhcp {
udp sport 68 udp dport 67 accept comment "dhcp"
}
chain dns {
ip protocol { tcp, udp } th sport 53 th sport 53 accept comment "dns"
}
chain ssh {
ip protocol tcp tcp dport 22 accept comment "ssh"
}
chain in_wan {
jump dns
jump dhcp
jump ssh
}
chain in_iot {
jump dns
jump dhcp
}
chain inbound {
type filter hook input priority filter; policy drop;
icmp type echo-request limit rate 5/second accept
jump conntrack
iifname vmap { "lo" : accept, "wlp1s0" : goto in_wan, "enp4s0" : drop, "wlp5s0" : goto in_iot }
}
chain forward {
type filter hook forward priority filter; policy drop;
jump conntrack
oifname "enp4s0" accept
}
}
table ip nat {
chain postrouting {
type nat hook postrouting priority srcnat; policy accept;
oifname "enp4s0" snat to 192.168.1.2
}
}
table ip6 global6 {
chain input {
type filter hook input priority filter; policy drop;
}
chain forward {
type filter hook forward priority filter; policy drop;
}
}
With this simple configuration, I expected KDE Connect to not work as it requires ports 1714-1764 to be open. And indeed, if I connect my computer to wlp1s0 and my phone to wlp5s0 (so different interfaces), the devices cannot see each other, and I can see the packets through tcpdump as well as through nftables, either using logging rules or nftrace.
But somehow if I now put both machines on the same interface, e.g. wlp1s0, KDE Connect works perfectly and the devices see each other. My best guess was that this happens because of connection tracking, but even if I add
chain trace_wan {
type filter hook prerouting priority filter - 1; policy accept;
iifname "wlp1s0" oifname "wlp1s0" meta nftrace set 1
}
to the filter table, I can't see any packets when running nft monitor trace. Similarly I can't see any packets in the system journal when inserting a logging rule at index 0 in the forward chain. And yet when running tcpdump -i wlp1s0 port 1716 I can see packets I expected nftables to see as well:
14:33:59.943462 IP 192.168.2.11.55670 > 192.168.2.42.xmsg: Flags [.], ack 20422, win 501, options [nop,nop,TS val 3319725685 ecr 2864656484], length 0
14:33:59.957101 IP 192.168.2.42.xmsg > 192.168.2.11.55670: Flags [P.], seq 20422:20533, ack 1, win 285, options [nop,nop,TS val 2864656500 ecr 3319725685], length 111
Why can nftables not see those packets when the two devices are connected on the same interface ? How can I make nftables actually drop all these forwarded packets by default ?
Additional information requested in the comments:
❯ ip -br link
lo UNKNOWN <LOOPBACK,UP,LOWER_UP>
enp2s0 DOWN <BROADCAST,MULTICAST>
enp3s0 DOWN <BROADCAST,MULTICAST>
enp4s0 UP <BROADCAST,MULTICAST,UP,LOWER_UP>
wlp5s0 UP <BROADCAST,MULTICAST,UP,LOWER_UP>
wlp1s0 UP <BROADCAST,MULTICAST,UP,LOWER_UP>
❯ ip -4 -br address
lo UNKNOWN 127.0.0.1/8
enp4s0 UP 192.168.1.2/24
wlp5s0 UP 192.168.3.1/24
wlp1s0 UP 192.168.2.1/24
❯ bridge link
❯ ip route
default via 192.168.1.1 dev enp4s0 proto static
192.168.1.0/24 dev enp4s0 proto kernel scope link src 192.168.1.2
192.168.1.1 dev enp4s0 proto static scope link
192.168.2.0/24 dev wlp1s0 proto kernel scope link src 192.168.2.1
192.168.3.0/24 dev wlp5s0 proto kernel scope link src 192.168.3.1
❯ sysctl net.bridge.bridge-nf-call-iptables
sysctl: error: 'net.bridge/bridge-nf-call-iptables' is an unknown key
|
Warning: this is a generic Linux answer. What won't be covered in this answer is specific integration with NixOS and its own method for configuring network or how to call arbitrary commands from its configuration.
Presentation
In OP's first case (two different interfaces), the router is actually routing between the two interfaces wlp1s0 and wlp5s0: forwarded IPv4 traffic is seen in nftables' family ip, filter forward hook.
In the second case, the traffic is bridged by the router's Access Point interface wlp1s0: nftables' family ip table doesn't see bridged traffic, only IPv4 traffic.
In addition this bridging doesn't even happens at standard Linux bridge level, but is done directly by the Access Point (AP)'s driver (and/or hardware accelerated): two Wifi devices will communicate between themselves (still through the AP) without their frames reaching the actual network stack.
In order for the system to actually filter this traffic, three things must be done:
change the AP's settings so that traffic goes through the network stack
have a Linux bridge associated to the AP so that frames aren't dropped by the network stack and so that nftables can see them at the bridge level
have adequate nftables rules in the bridge family. For IP stateful firewalling in the bridge family, this also requires Linux kernel >= 5.3 (NixOS 22.11 is good enough).
Other options not pursued:
alternatively to 2+3, and without possible stateful firewalling, one might imagine using nftables' netdev family with ingress and possibly egress (requires Linux kernel >= 5.17 for egress fwd) but there would be many corner cases to handle: better not
instead of 3, use old bridge netfilter code intended for stateful firewalling in bridge path by iptables (and used by Docker) to have all rules in the same table
nftables, which is also affected by it, aims to not depend on this code and thus lacks features for its proper use (mostly it lacks the equivalent of iptables' physdev module for one way to distinguish bridged traffic from routed traffic in the same ruleset). This would make things still rely on iptables and would thus still need multiple tables. (Example of such complex use along Docker: nftables whitelisting docker).
As a warning, should Docker be added on the router, expect disruption of the setup presented below.
Setup
change hostapd settings
Two related settings must be changed on the hostapd setup:
tell that frames must be handled by the network stack rather than being short-circuited by the driver
The configuration of hostapd for wlp1s0 must be changed. If somehow a single configuration existed for the two Wifi interfaces, chances are there should now be two separate configurations. I won't address such integration in this answer and will concentrate on the single interface wlp1s0.
AP isolation must be enabled in hostapd.conf:
ap_isolate=1
Now frames between two station clients (STA) will reach the network stack rather than being handled directly by the AP driver.
Configure hostapd to use a bridge and set the wireless interface as bridge port
With only the previous setting, only the frames to or from the router would be handled by the routing stack part of the network stack. Frames not intended for or coming from the router would simply be dropped, as would happen if an Ethernet interface received unicast frames not intended for its MAC address. That's also why the setting is named ap_isolate: by default STAs become isolated between themselves.
A bridge is required to handle this. Tell hostapd to set wlp1s0 as bridge port as soon as it configured it in AP mode. It will either create a bridge or (to be preferred) reuse an existing bridge with the provided name and set the interface as bridge port when running. I chose the arbitrary name brwlan1.
Configure the bridge in hostapd.conf:
bridge=brwlan1
change network settings related to using a bridge
configure the bridge with no attached port and no delay
Manually that would just be:
ip link add name brwlan1 up type bridge forward_delay 0
Note: hostapd is the tool that will attach the Wifi interface to the bridge, because it must be set as AP first before being allowed to be set as bridge port.
move any routing (layer 3) setup about wlp1s0 to brwlan1:
ip addr delete 192.168.2.1/24 dev wlp1s0
ip addr add 192.168.2.1/24 dev brwlan1
This also includes changing any interface reference in various applications, for example in the DHCP settings.
...and also nftables but this will be dealt in the next part.
have hostapd running
Verify that once its wlp1s0 instance is running, wlp1s0 is set as brwlan1 bridge port:
One should see something similar to:
# bridge link show dev wlp1s0
6: wlp1s0 <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master brwlan1 state forwarding priority 32 cost 100
then enable hairpin mode on the single bridge port
For now, there still can't be STA-to-STA communication, but only STA-to-AP or AP-to-STA: STA-to-STA requires a frame arriving on the single bridge port wlp1s0 to be re-emitted on this same bridge port. Even if there's now a bridge to forward such frames, they won't be yet: by default an Ethernet bridge (or switch) disables forwarding back to the originating port because it doesn't make much sense in normal wired setup.
So hairpin must be enabled on wlp1s0 so a frame received on this port can be re-emitted on this same port. Currently only development version (branch main) of hostapd accepts the new configuration parameter bridge_hairpin=1 to do this automatically (version 2.10 is not recent enough). This can be done manually using the bridge command (the obsolete brctl command doesn't support this feature):
bridge link set dev wlp1s0 hairpin on
This part requires proper OS integration: it must be done only after hostapd attached wlp1s0 as bridge port, because it's usable only on a bridge port. I would expect hostapd to set wlp1s0 as bridge port before daemonizing and letting the network configuration tool then run the command. Should that not be the case and a race condition happen, one can consider simply inserting a delay (eg: sleep 3; ) before this command to be sure the interface is a bridge port when the command runs. Should wlp1s0 be detached/reattached with the bridge (eg: restart of hostapd), this command must be run again: it should be called from network configuration.
adapt nftables ruleset
... using the bridge family instead of the ip family. It's quite similar to routing. Frames intended for the router are seen in input hook, frames from the router are seen in output hook, STA-to-STA frames are seen in the forward hook.
As objects namespace is per table, there can't be any rule reused between both, so some duplication will be needed. I just copied and adapted the relevant parts of the routing rules related to forwarding. As an example I enabled ping and the ports for KDE connect, with a few counters. Some of the boiler-plate is not really needed (eg: ether type ip ip protocol tcp tcp dport 1714 can be replaced with just tcp dport 1714 if there's a generic drop rule for IPv6 first. Internally the nft command inserts any needed boiler-plate when presenting the rules to the kernel).
table bridge filter # for idempotence
delete table bridge filter # for idempotence
table bridge filter {
chain conntrack {
ct state vmap { invalid : drop, established : accept, related : accept }
}
chain kdeconnect {
udp dport 1714-1764 counter accept
tcp dport 1714-1764 counter accept
}
chain forward {
type filter hook forward priority filter; policy drop;
jump conntrack
ether type ip6 drop # just like OP did: drop any IPv6
icmp type echo-request counter accept
jump kdeconnect
ether type arp accept # mandatory for IPv4 connectivity
counter
}
}
Should wlp5s0 be later configured likewise with its own separate bridge, then filtering per bridge port or per bridge will become needed (eg: iifname wlp1s0 or ibrname brwlan1 etc. where needed).
Other cases are still handled by standard routing in OP's initial ruleset: the input and output filter hooks are not configured so will accept traffic, either to/from the router, or to be routed to/from other interfaces.
OP's nftables for routing must be adapted too. Wherever in table ip filter the word wlp1s0 appears, it must be replaced by brwlan1 which is now the interface participating in routing.
| nftables doesn't see KDE Connect packets between two machines on the same interface |
1,577,654,170,000 |
When I run sudo ufw status on a Ubuntu box, I get the following output
sudo ufw status
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
30303 ALLOW Anywhere
9000 ALLOW Anywhere
3000 ALLOW Anywhere
80/tcp ALLOW Anywhere
8008/tcp ALLOW Anywhere
8008 ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
30303 (v6) ALLOW Anywhere (v6)
9000 (v6) ALLOW Anywhere (v6)
3000 (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
8008/tcp (v6) ALLOW Anywhere (v6)
8008 (v6) ALLOW Anywhere (v6)
When I access a service running on port 8008 from within the box using localhost it works. That is, the following works:
curl --head http://localhost:8008/metrics
But if I use the IP address of the box instead, it does not work. That is:
$ curl --head http://<public-ip>:8008/metrics
curl: (7) Failed to connect to <public-ip> port 8008: Connection refused
And If I also try accessing from the browser, it is still connection refused.
What could be going on here? The output of sudo ufw status shows that the port is open and accessible, but it is still not working.
Edit:
As requested in the comments:
netstat -tln | grep 8008
tcp 0 0 127.0.0.1:8008 0.0.0.0:* LISTEN
ss -tln | grep 8008
LISTEN 0 511 127.0.0.1:8008 0.0.0.0:*
|
The answer is in the output of netstat. You are listening on address127.0.0.1. You probably need to listen on 0.0.0.0 (all local interfaces/addresses).
Thanks to the other commenters for working it out.
| Why am I getting connection refused with IP address even though it works with localhost and firewall is open? |
1,577,654,170,000 |
While messing around in a qemu guest I discovered something very peculiar. If I set the system firewall to reject all traffic to my gateway (10.0.2.2), the firewall only rejects traffic destined to the gateway directly. Traffic not destined to 10.0.2.2 seemingly continues to get routed and flows through the gateway as if the rule wasn't there at all.
As I understand it from the perspective of the guest (10.0.2.15):
Packet{dest==10.0.2.0/24} 10.0.2.15 -x-> 10.0.2.2 (Rejected)
Packet{dest!=10.0.2.0/24} 10.0.2.15 <--> 10.0.2.2 <-> !=10.0.2.0/24 (Okay)
This is completely contrary to what I expected. I assume there is something I'm missing but I don't know what.
Here is my setup:
Firewall Rule:
ufw reject out to 10.0.2.0/24
Output of ip route:
default via 10.0.2.2 dev ens3 proto dhcp metric 100
10.0.2.0/24 dev ens3 proto kernel scope link src 10.0.2.15 metric 100
The relevant part of output of iptables -S seems to be:
-A ufw-user-output -d 10.0.2.0/24 -j REJECT --reject-with icmp-port-unreachable
|
This is working and not blocked because a gateway routes packets with source and destination IP addresses that are not the gateway's address. No IPv4 packet (see later about ARP) with address 10.0.2.2 is used to successfully route through the gateway with IP address 10.0.2.2/24.
So when 10.0.2.15 sends a packet to 8.8.8.8 this packet has source 10.0.2.15 and destination 8.8.8.8. This packet has no destination 10.0.2.2 and thus no destination within 10.0.2.0/24: pass.
The only packets with the IPv4 address 10.0.2.2 in their payload indirectly involved with routing through the gateway are not IPv4 packets. They are ARP packets used by the VM system to discover (and cache in its ARP table) the Ethernet MAC address of the gateway's interface. IPv4 traffic for "outside": matching the route with the gateway, is then sent at the link layer (Ethernet) to this MAC address (and not to the IP address 10.0.2.2).
ARP is not filtered by iptables which is the backend of UFW, so can't be blocked with UFW. It could be with arptables for example, but useful use case is not very common.
Notes
DHCP (IPv4)
If 10.0.2.2 is also a DHCP server to the VMs this might possibly or not (depending on the exact technology in use) prevent at some point later DHCP communication to work properly or force the VM to do a broadcast DHCP DISCOVER instead of an unicast DHCP REQUEST. If the lease were to be lost possibly a few hours later, so would the IP address and thus routes and thus indirectly the connectivity through the router.
Usually that's not the case, because usually DHCP on Linux has to rely on RAW sockets (for example to handle source address 0.0.0.0 properly) which bypass all of iptables rules.
IPv6
As the link layer resolution protocol for IPv6 is not ARP but using ICMPv6, thus part of IPv6 and filtered by ip6tables, some assumptions valid for IPv4 are not valid for IPv6. For example indiscriminately blocking ICMPv6 usually results in very fast loss of IPv6 connectivity and removal of routable IPv6 address acquired through SLAAC, while blocking indiscriminately ICMP for IPv4 usually works fine (beside possible PMTUD blackhole problems).
| Why does traffic continue to flow through my gateway despite a firewall rule blocking all outbound traffic addressed to it? |
1,626,650,735,000 |
I freshly install openBSD on a VPS. It is my first time. I did nothing but check the firewall setup, say pf. I ran pfctl -sa and it show
all tcp IP0:22 <- IP1:rnd ESTABLISHED:ESTABLISHED
all tcp IP0:22 <- IP2:rnd ESTABLISHED:ESTABLISHED
all tcp IP0:22 <- IP3:rnd FIN_WAIT_2:FIN_WAIT_2
all tcp IP0:22 <- IP4:rnd TIME_WAIT:TIME_WAIT
with IP0 my server IP, IP1 my local IP, but IP2, IP3, IP4, are completely unknown IP to me. There is some repetitions of the last two lines with diferent port number (rnd). I tried to understand the information in the table with few success, I am completely a newby in web traffic and so on...
Should I be preoccupated with that second line which suggest a third party is connected to my server?
Thanks!
|
The second line doesn't mean that someone is logged in, it merely indicates that someone made a connection to the port. After connecting, the client will then try to authenticate itself, using the established connection.
If you are still suspicious you can test this yourself: log in via SSH on one terminal, open another terminal and run ssh and wait at the password prompt. Now run pfctl -sa on the other terminal and you'll see your IP come up twice: one for the logged in terminal and another for the 'waiting' connection.
/var/log/authlog should show you the list of all successful and failed login attempts.
| PF states table give preoccupant results |
1,626,650,735,000 |
Fresh Webmin install on Ubuntu 20.04 on Amazon Lightsail
I added the line to iptables as per their instructions:
sudo iptables -A INPUT -p tcp -m tcp --dport 10000 -j ACCEPT
I have added port 10000/tcp to ufw also.
When I go to the browser https://myip:10000 the browser stays loading for a while then says:
cant open the page because the server where this page is located isn't responding
What am I missing?
Edit:
When I run sudo service webmin status I get this:
● webmin.service - LSB: web-based administration interface for Unix systems
Loaded: loaded (/etc/init.d/webmin; generated)
Active: active (exited) since Thu 2021-02-04 00:52:06 UTC; 55min ago
Docs: man:systemd-sysv-generator(8)
Feb 04 00:52:05 ip-172-26-4-221 systemd[1]: Starting LSB: web-based administration interface for Unix systems...
Feb 04 00:52:05 ip-172-26-4-221 perl[4800]: pam_unix(webmin:auth): authentication failure; logname= uid=0 euid=0 tty= ruser= rhost= user=root
Feb 04 00:52:06 ip-172-26-4-221 webmin[4800]: Webmin starting
Feb 04 00:52:06 ip-172-26-4-221 systemd[1]: Started LSB: web-based administration interface for Unix systems.
lines 1-9/9 (END)
|
@OKOK Are you on LightSail?
For me it was the Amazon firewall. I had to allow port 10000 through LightSail console under Network. Even though I had allowed it on ufw through terminal Amazon was applying its own firewall.
| Can't access Webmin from browser after installing |
1,626,650,735,000 |
I have host used as gateway with
net.ipv4.conf.all.rp_filter=0
and iptables rpfilter that is used instead
iptables -t raw -A PREROUTING -m rpfilter --invert -j LOG-DROP-RP
My host have 2 interfaces eth1 with IP 10.0.0.1/8 and eth2 with IP 192.168.0.1/16.
If some host with IP 192.168.0.2 on eth1 send packet it's dropped and logged.
Forwarding table also block forwarding between eth1 and eth2. Packet from 10.0.0.2 on eth1 to 192.168.0.2 on eth2 blocked and logged by forwarding rules.
But if host with IP 10.0.0.2 on eth1 send packet to 192.168.0.1 it will pass. rpfilter just ignores it. Forwarding table seems to be ignored as well.
How do I prevent it? Because there may be some private interface eth3 on this host with private service listening on it and it can be accessed from anywhere which is unwanted.
|
Linux uses the weak host model: any IP address assigned to any interface belongs to the host as a whole. When you reach from 10.0.0.2 to 192.168.0.1 there's no forwarding involved because the destination address belongs to the host: the packet gets handled by filter/INPUT, not by filter/FORWARD (which thus won't be evaluated for this packet). A detailed schematic of the packet's trip can be found there.
This is not a routing anomaly, so this won't trigger Strict Reverse Path Forwarding, be it set in the routing stack or in iptables's rpfilter module.
So you have to also add explicit rules for this with IP addresses. If still wishing to put this in the raw table, the addrtype match works even there to figure out if the destination is local (or also broadcast). You can add after the SRPF test these rules (which would work if multiple IP addresses were assigned to the host rather than just the .1 ones):
iptables -t raw -A PREROUTING -s 10.0.0.0/8 ! -d 10.0.0.0/8 -m addrtype --dst-type LOCAL,BROADCAST -j DROP
iptables -t raw -A PREROUTING -s 192.168.0.0/16 ! -d 192.168.0.0/16 -m addrtype --dst-type LOCAL,BROADCAST -j DROP
I wouldn't know with iptables how to add generic rules that will not include details related to the specific addresses in use. It's possible with nftables:
# drop packets to address not configured on incoming interface
filter prerouting fib daddr . iif type != { local, broadcast, multicast } drop
| iptables does not block forwarding to another IP of the host itself |
1,626,650,735,000 |
On a random day I was googling iptables rules to harden my desktop, and came across this post[1]. At some point the guide mentions blocking invalid TCP packets using tcp-modules with these rules;
iptables -A INPUT -p tcp -m tcp --tcp-flags ALL FIN,PSH,URG -j DROP
iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
iptables -A INPUT -p tcp -m conntrack --ctstate NEW -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -j DROP
I pressed return on the above commands and the rules were applied successfully. Then I tried replacing the tcp portions on each of the commands with udp for eg, in case of the 3rd command I'd do,
iptables -A INPUT -p udp -m conntrack --ctstate NEW -m udp ! --udp-flags FIN,SYN,RST,ACK SYN -j DROP
Which returned me an error saying these rules are not valid for udp packets. I am on a Debian OS, Kernel version 4.9.x
The article I was reading online
https://www.booleanworld.com/depth-guide-iptables-linux-firewall/
|
TCP is a stateful protocol, UDP is stateless, so you cannot use ctstate with it.
Either you let traffic for a particular port for UDP or you don't.
Also --udp-flags FIN,SYN,RST,ACK SYN is just pure nonsense.
In short familiarize yourself with TCP/IP and UDP a bit before rushing to set up iptables.
| Why is it that TCP packets can be modified to block invalid packets, but not UDP packets |
1,626,650,735,000 |
I have opened the 3000 port of my CentOS 7 server with the following commands:
firewall-cmd --zone=public --add-port=3000/tcp --permanent
firewall-cmd --reload
But now I want to closing them, how can I do that?
|
firewall-cmd --zone=public --remove-port=3000/tcp --permanent
should do the trick.
man firewall-cmd is always at your disposal.
| how to close a port on CentOS 7 server? |
1,626,650,735,000 |
I've got my server set up with long list of services, and everything is working great... on IPv4. But when I test them against IPv6 nothing is resolving. After disabling nftables everything started working, so I turned it back on and through trial and error, was able to identify the two lines (identified with --> below) that were causing things to fail...
# Accept related or established, drop bad, accept everything else
add rule inet filter INPUT ct state related,established accept
add rule inet filter INPUT tcp flags & (fin|syn|rst|psh|ack|urg) == 0x0 drop
--> add rule inet filter INPUT tcp flags & (fin|syn|rst|ack) != syn ct state new drop
--> add rule inet filter INPUT tcp flags & (fin|syn|rst|psh|ack|urg) == fin|syn|rst|psh|ack|urg drop
add rule inet filter INPUT iifname "lo" accept
I'm not as educated as I should be on TCP, actually I'm just educated enough to get myself into trouble, so I'd appreciate some help interpreting what I'm doing here. My understanding is that I'm accepting all related/established traffic, and all traffic related to the loopback interface. I'm really just looking at "new" requests...
My problem is that I don't really understand the TCP flags other than syn and ack (and really only insofar as how they work in a three way TLS handshake), the others I've added here just seemed to be common in the tutorials I was reviewing. My fear is I don't understand the implication of leaving them there, or taking them out and what I'm opening myself up to. My goal is to allow IPv4 and IPv6 traffic, while eliminating any bad or unrelated packets from getting through.
This will eventually be tied to a commercial offering, so I'd like to understand better but need a little guidance. Would appreciate anyone helping clear this up with me.
EDIT: Turns out these were not the issue, the rules that were causing the issue were actually the icmp rules, IPv6 requires a handful of nb-* rules in order to operate properly. I'll provide details in an answer.
|
Turns out that the rules I posted were not the culprit, as I've noted in the question update. The actual issue was related to ICMP traffic and in particular several types related directly to IPv6. My ICMP rules were...
add rule inet filter INPUT ct state new icmp type { echo-request, echo-reply } accept
add rule inet filter INPUT ct state new icmpv6 type { echo-request, echo-reply } accept
But in order to operate properly IPv6 requires a number of Neighbour Discovery related rules (nd-*). I've included them as well as a few other types that are all part of being a "good network citizen". The ones I thought were the issue were actually important for attack mitigation and are working fine now that I've fixed my ICMP traffic.
The new ICMP rules are...
add rule inet filter INPUT ip protocol icmp icmp type { destination-unreachable, echo-reply, echo-request, source-quench, time-exceeded } accept
add rule inet filter INPUT ip6 nexthdr icmpv6 icmpv6 type { destination-unreachable, echo-reply, echo-request, nd-neighbor-solicit, nd-router-advert, nd-neighbor-advert, packet-too-big, parameter-problem, time-exceeded } accept
The original rules I thought were the issue are actually for mitigating malicious behaviour...
XMAS Attack This rule is for mitigating the XMAS attack, or one that enables the packet bits for all tcp types, otherwise, lighting it up like a "Christmas tree" in order to parse the slight differences in OS responses to such a request to help identify further avenues of attack by a bad actor...
add rule inet filter INPUT tcp flags & (fin|syn|rst|psh|ack|urg) == fin|syn|rst|psh|ack|urg drop
Force SYN check If I understand it right, this helps to lower the processing load by eliminating other useless packets that precede the initial SYN packet that could be part of an attack on resources, like a denial of service via resource exhaustion...
add rule inet filter INPUT tcp flags & (fin|syn|rst|ack) != syn ct state new drop
This post helped me get a foothold and start searching out a better understanding.
Hope this provides a shortcut to the answer for someone else! :)
| nftables preventing services from resolving on IPv6 |
1,626,650,735,000 |
I had question about IPtables.
Let's start with this example of my book:
What rules you would set for a mail server accepting connections for
EMSTP (port 465) and IMAP (port 993) having a network interface eth1
exposed to the Internet and another network interface eth2 exposed to
the corporate network?
I tried to respond with this:
Iptable -A FORWARD -p EMSTP, IMAP -s all -i eth1 -m multiport 465,993 state –state NEW, ESTABILISHED -j ACCEPT
Iptable -A FORWARD -p EMSTP, IMAP -s all -i eth2 -m multiport 465,993 state –state NEW, ESTABILISHED -j ACCEPT
I thought about FORWARD because isn't specified if traffic is INPUT
or OUTPUT... So I used the generic in/out (FORWARD if I can use in
this mode)
The protocol is specified(so I think don't have problems about)
I Used two rules because I used different interface, but I think
can do all in the same rules, just adding another -i inside the same rule.
For the network, I think that one is (internet) and another one is
local network (I really don't know what mean for "corporate")
My question is if my response is good and if it is mandatory to use this type of format.
What change is I swap the order of the rules?
In this case ad example:
Iptable -A FORWARD -j ACCEPT -i eth1 -p EMSTP, IMAP -s all -m multiport 465,993 state –state NEW, ESTABILISHED
Just swapping the jump and the inteface (-j and -i)
Someone can help to understand?
|
First, some reminders:
-p argument is to specificy protocols like TCP, UDP, ICMP ... not higher level protocol like IMAP.
OUTPUT and INPUT chains are for the packets outgoing from the machine and incoming to the machine. If you want to filter packets that are forwarded (when your machine act as a gateway), you must use the FORWARD chain. To distinguish IN and OUT, use the input or output interfaces and the source and destination IPs
ESTABILISHED --> typo !!! :)
Now, let's have a look to your problem:
What rules you would set for a mail server accepting connections for EMSTP (port 465) and IMAP (port 993) having a network interface eth1 exposed to the Internet and another network interface eth2 exposed to the corporate network?
The problem is too broad since it says that:
The machine is a mail server.
It has two interfaces
It must accept connections for mail related protocols.
But it isn't said that the connections must be accepted for both networks (internet / corporate). Anyway, let's assume that it is the case.
iptables works with discriminants: -i is one to match packets incoming to THAT interfaces.
Since you want the traffic to be accepted on every interfaces, then simply remove -i.
As mentionned previously, -p is to specify the transport protocol. Mails work in TCP, so use ̀ -p tcp`.
So your first responses would work (minus typo and some syntax error, the idea is OK).
Your last won't cause it allows packets coming from internet (eth1) to pass throught your server and go to your corporate network.
| Iptable order of rules with example |
1,626,650,735,000 |
I have few vms (homelab) virtualized with KVM (CentOS7) and connected to my home network. Lately I tried to isolate them by putting them in separate network and I wanted to do so with virtualized pfsense on the same host as other vms.
First I created isolated network in virt-manager for my lab hosts.
Then I created vm with 2 NICs and installed pfsense. One interface has 192.168.1.100 address (home lan) and the other one 10.13.37.1 (lab network).
pfsense xml dump:
<interface type='direct'>
<mac address='52:54:00:52:37:3f'/>
<source dev='enp1s0' mode='bridge'/>
<target dev='macvtap0'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<interface type='network'>
<mac address='52:54:00:65:58:d6'/>
<source network='lab' bridge='virbr1'/>
<target dev='vnet1'/>
<model type='virtio'/>
<alias name='net1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</interface>
I moved one of my vms (test server) to the internal pfsense network and set pfsense ip address as a gateway, to test if I will be able to connect to the internet.
test server (10.13.37.54) xml dump:
<interface type='network'>
<mac address='52:54:00:eb:ce:db'/>
<source network='lab' bridge='virbr1'/>
<target dev='vnet0'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
There is www server running on the test server and I can curl it (curl http://10.13.37.54) from pfsense vm so internal network is working fine. I also have internet connection on the pfsense (I can update os and, for example, curl http://google.com). From the test server I can ping pfsense and google.com, but when I try to curl http://google.com I'm constantly getting timeouts for some reason (same for other sites). I can resolve the google.com domain to IP so dns (udp packets) is working fine, but I can't establish TCP 3-way handshake. I'm sending SYN packet, but not getting anything back. Here's how packets capture from internal lab network looks like (captured on pfsense):
|
I've got the answer on the other forum, turns out that all I had to do was disable hardware checksum offload, link to the documentation
| Virtualized firewall on KVM |
1,626,650,735,000 |
I'd like to locally test my web application's behavior under different firewall circumstances.
We have an application that makes requests from the browser to different ports depending upon certain conditions, and I'd like to set up a firewall that allows me to modify firewall rules dynamically so as to see how the application behaves when a port is disabled.
I'd like to do this by setting up a firewall that blocks requests from my machine to a port on a guest machine.
I'm running OS X Sierra with Virtualbox, using pfctl.
I started with this command (on the host), attempting to block ports on the guest (at 192.168.99.100), but I haven't had any success:
block in quick inet proto { tcp, udp } from any to 192.168.99.100 port 63342
|
This seems a little counter intuitive to me in how you're approaching it. Typically you'd setup the firewall on the actual server where the web application is residing.
If you're using firewalld this is pretty trivial. You can see the names of all the services it's able to deal with by name using this command:
$ firewall-cmd --get-services
web names
$ firewall-cmd --get-services | grep -oE '\shttp[s]*'
http
https
To allow these two protocols into the VM:
$ firewall-cmd --permanent --add-service http --add-service https
success
$ firewall-cmd --reload
success
Your firewall is now configured like so:
$ firewall-cmd --list-all
public (active)
target: DROP
icmp-block-inversion: no
interfaces: eth0 eth1
sources:
services: ssh dhcpv6-client http https
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
The above states that 4 services are allowed in, everything else will get dropped (DROP) based on the default target.
References
How To Set Up a Firewall Using FirewallD on CentOS 7
RHEL7: How to get started with Firewalld.
| How to set up a firewall for testing web applications in a virtual machine? [closed] |
1,626,650,735,000 |
I have set up this rule:
-A PREROUTING -i vboxnet0 -p tcp -m tcp --dport 80 -j internet
-A internet -j MARK --set-xmark 0x63/0xffffffff
To capture incoming traffic on port 80 and send it to be marked. It works, but now I'd like to edit it to capture on all ports except 53(DNS), the DHCP service port and some others.
Further down my iptables, I have
-A PREROUTING -i vboxnet0 -p tcp -m mark --mark 0x63 -m tcp --dport 80 -j DNAT --to-destination 192.168.56.1
That captures all tcp traffic, that has the mark, and is destined for port 80, and DNAT it to the local IP. I'd like to edit this to also include all ports except 3(DNS), the DHCP service port and some others.
Some good pointers in lieu of a small explanation of the difference between the first -m and the second -m in both rulesets could also get me on the correct track.
|
Understanding Your Rules
The first step in understanding how your firewall rules work is, like in most things, to check the man page (man iptables). In the man page you will find:
-m, --match match
Specifies a match to use, that is, an extension module that tests for a specific property. The set of matches make up the condition under which a target is invoked. Matches are evaluated first to last as specified on the command line and work in short-circuit fashion, i.e. if one extension yields false, evaluation will stop.
Near the bottom of the man page you'll also find:
MATCH AND TARGET EXTENSIONS
iptables can use extended packet matching and target modules. A list of these is available in the iptables-extensions(8) manpage.
So then the iptables-extensions man page will give you the specifics on what your -m options are really doing. A few small snippets from there:
mark
[!] --mark value[/mask]
...
tcp
[!] --destination-port,--dport port[:port]
...
DNAT
This target is only valid in the nat table, in the PREROUTING and OUTPUT chains, and user-defined chains which are only called from those chains. It specifies that the destination address of the packet should be modified (and all future packets in this connection will also be mangled), and rules should cease being examined. It takes the following options:
--to-destination [ipaddr[-ipaddr]][:port[-port]]
...
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.
--set-xmark value[/mask]
To put it simply, the -m options adds matching options to iptables. But the man page also lists some non-standard targets (including the DNAT that you're using.
What to Do
Now, putting all of this together I assume that the table you're working with is nat given it's the only one that works with DNAT target.
It also seems that marking the traffic is unnecessary. It's simply being marked so that you can nat the packet, but you can just nat the packet instead of tagging it to begin with.
For example:
-A PREROUTING -i vboxnet0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.56.1
You can specify multiple rules to cover multiple ports, but also specify port ranges using [port]:[port], or negative matches using !.
For example, to apply the rule to all ports except 53 (domain) and 22 (ssh) you could do the following:
-A PREROUTING -i vboxnet0 -p tcp -m tcp ! --dport 53 -j DNAT --to-destination 192.168.56.1
-A PREROUTING -i vboxnet0 -p tcp -m tcp ! --dport 22 -j DNAT --to-destination 192.168.56.1
It could get cumbersome if there's lots of ports you want to filter out, but such is life with iptables. I'd recommend checking /etc/services to get a list of port mappings so you can avoid impacting certain services/protocols.
| How to Redirect marked packets on multiple ports to one IP Address |
1,626,650,735,000 |
Iptables is not blocking connections to devices connected to a bridged router. I have inserted the rules at the top of the rules list with: iptables -I INPUT -d 216.58.201.46 -j DROP
Result:
root@OpenWrt:~# iptables -L INPUT -v -n
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 DROP all -- * * 216.58.201.46 0.0.0.0/0
0 0 DROP all -- * * 0.0.0.0/0 216.58.201.46
127 14720 delegate_input all -- * * 0.0.0.0/0 0.0.0.0/0
I am still able to ping the IP from my laptop connected to the router with the rules, though I cannot ping the IP directly from the router as expected.
|
The INPUT table is for packets whose destination is your OpenWRT router itself. Use the FORWARD table for packets going through your router to/from your devices.
iptables -I FORWARD -d 216.58.201.46 -j DROP
| iptables not blocking, bridged router |
1,626,650,735,000 |
I am having difficulties configuring NAT with iptables on my firewall.
My firewall setup is as follow:
it is a layer 2 transparent firewall, between my gateway and my ISP's gateway
I bridged two interfaces as br0. The two interfaces are eno0 on my ISP side and eno1 on my local network side
I set up basically no iptables rules except one for NAT
Here are my rules:
root@firewall:~# iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
root@firewall:~# iptables -t nat -S
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-A POSTROUTING -s 10.50.1.0/24 -j SNAT --to-source xxx.195.142.205
root@firewall:~# iptables -t mangle -S
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
The problem is, in short, that address translation works for outgoing traffic but not for the replies. Here is a test example:
I connected a laptop with IP 10.50.1.7 on my LAN and used it to ping 8.8.8.8
on the firewall, with tcpdump -i eno1, I see ICMP requests from 10.50.1.7 to 8.8.8.8, but no replies
on the firewall, with tcpdump -i eno0, I see ICMP requests from xxx.195.142.205 to 8.8.8.8, and the ICMP replies from 8.8.8.8 to xxx.195.142.205
Obviously, on the laptop, I do not get the ICMP replies
So the replies are not translated back to the local IP. What am I missing ?
Thanks for your help!
(NB: when removing the NAT rule and using the public IP xxx.195.142.205 on the laptop, I have full internet access)
|
As suggested by @dirkt, it looks like conntrack does not work well with a bridge. So iptables rules that don't require seem to work on a bridge, but not NAT.
Problem solved as soon as I configured my firewall as a layer 3 firewall.
In case others are interested: I extensively searched the Web if it was possible to use a transparent layer 2 firewall with NAT, but never got a straight answer.
ebtables website do suggest that it is possible:
bridge-nf code makes iptables see the bridged IP packets and enables
transparent IP NAT.
I never found out which ebtables command would make it work though.
| Use NAT with iptables and a bridge |
1,626,650,735,000 |
I am not able to get my ufw rules working. As far as I understand, the default behavior is to deny all incoming connections thus the command
ufw allow from 192.168.4.3 to any port http
should enable incoming http connections for the specific ip. However, the requests are blocked by the firewall. I've also tried to explicitly deny and then allow but it isn't working either.
The output of ufw status verbose is
To Action From
-- ------ ----
631/tcp ALLOW IN Anywhere
22 ALLOW IN Anywhere
80 ALLOW IN 192.168.4.3
631/tcp (v6) ALLOW IN Anywhere (v6)
22 (v6) ALLOW IN Anywhere (v6)
The output of netstat -tulnp | grep :80 is
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 336/nginx: master p
Which part of the config / concept am I missing?
|
Check the log /var/log/ufw.log. The default logging level (low) should record any blocked requests. Make sure the source IP (SRC field) matches the IP address you are expecting.
| Unable to allow specific ip addresses in ufw |
1,626,650,735,000 |
I try to connect a NIS server on CentOS 7.3 and a NIS client on raspbian 8.0 together.
My problem is that raspbian does not want to bind the server.
journalctl server the following entry:
raspberrypi nis[708]: Starting NIS services: ypbindbinding to YP server...........................................failed (backgrounded).
If I configure raspbian to be the NIS server and the NIS client also, ypwhich command bring good result, it shows the hostname of itself (raspberrypi) and log entry does not exist I mentioned above. When I change back to NIS client mode only, and set up the configuration to look the server on CentOS 7, ypwhich says that the domain just not connected.
After readind several how to-s, I found someone's advice that firewall and SELINUX rules should be checked also.
I'm inexperienced with doing this.
Can someone give the commands how to disable the firewall and/or SELINUX rule against NIS service?
|
Try to use this command
setenforce 0
the restart the ybind service
service ypbind stop
service ypbind start
if it doesnt work then the firewall on the NIS server is blocking all connections from the NIS client. you can stop it using
systemctl disable firewalld
to disable it or
systemctl stop firewalld
to stop it
you can check the status of firewalld using the following command:
systemctl status firewalld
| How to disable all firewall rules and SElinux if runs on CentOS7 |
1,626,650,735,000 |
This tutorial shows how to set up an easy parental control facility, with help of DansGuardian, Privoxy and a few firewall rules. I've tested it and so far, it seems to be working for most part.
There are, however, some things I fail to understand. Namely, in this tutorial we are told to set up, among others, following firewall rules:
sudo iptables -A OUTPUT -p tcp -m multiport --dports 80,443 -m owner --uid-owner privoxy -j ACCEPT
sudo iptables -A OUTPUT -o lo -p tcp --dport 8118 -m owner --uid-owner dansguardian -j ACCEPT
Wait... -m owner --uid-owner dansguardian, -m owner --uid-owner privoxy??
I always thought that uids can be either usernames or groups, which can be assigned to users, and not processes or files? I must've been wrong...
This is even more confusing because getent group shows an entry for dansguardian, but not for privoxy; so I'm not sure what does this --uid-owner privoxy refers to, since privoxy is neither a user nor group.
Thanks in advance for explaining this to me.
|
I always thought that uids can be either usernames or groups
Those are user names. It's intended that you run Privoxy under a user called prixovy and DansGuardian under a user called dansguardian.
This is even more confusing because getent group shows an entry for dansguardian, but not for privoxy
Do cat /etc/passwd to see the list of users. Most likely, privoxy is a user on your system if you installed the privoxy package in Debian or Ubuntu. There might not be a corresponding group as there is for dansguardian.
| How can we set firewall rules to allow or deny specific programs? |
1,626,650,735,000 |
I have a working port knocking setup for SSH on Linux using only iptables rules and the “recent” module following this tutorial: https://wiki.archlinux.org/index.php/Port_knocking#Port_knocking_with_iptables_only .
Now my problem is that several networks like my work network block traffic to non-standard ports like 22, 80, 443, so I can‘t send my knock packets. On the other hand, my mobile internet allows them.
As a workaround I would like to open the SSH port whenever the correct knocking sequence is sent from any host, not just the same host.
is there some way to achieve that with iptables? E.g. I could imagine a “state switch” or global variable that can be switched on by one rule and checked by another rule. It would fall back to “off” after a timeout.
|
I would suggest to go knockd route. It's simpler this way. Only instead of using this default config
[openSSH]
sequence = 7000,8000,9000
seq_timeout = 10
tcpflags = syn
command = /usr/sbin/iptables -A INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
[closeSSH]
sequence = 9000,8000,7000
seq_timeout = 10
tcpflags = syn
command = /usr/sbin/iptables -D INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
You would use this one (Note -s %IP% removed)
[openSSH]
sequence = 7000,8000,9000
seq_timeout = 10
tcpflags = syn
command = /usr/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
[closeSSH]
sequence = 9000,8000,7000
seq_timeout = 10
tcpflags = syn
command = /usr/sbin/iptables -D INPUT -p tcp --dport 22 -j ACCEPT
| Allow SSH access after port knocking from any source IP |
1,626,650,735,000 |
at the moment I'm trying to implement the firewall for my linux file server. Everything is working as expected except form the samba server. I have searched through the internet already but non of the solutions works for me. If the firewall is disabled samba works fine. If I add my samba rules I'm unable to access the server via Windows. What's my mistake?
Many Thanks,
Jonny
# 1. Delete all existing rules
iptables -F
# 2. Set default chain policies
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
#Allow traffic on loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
#dhcp
iptables -I INPUT -i eth0 -p udp --dport 67:68 --sport 67:68 -j ACCEPT
#samba server
iptables -A INPUT -i eth0 -s 192.168.178.0/24 -p udp --dport 137:138 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -d 192.168.178.0/24 -p udp --sport 137:138 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -s 192.168.178.0/24 -p tcp --dport 139 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -d 192.168.178.0/24 -p tcp --sport 139 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -d 192.168.178.0/24 -p tcp --dport 445 -m state --state ESTABLISHED -j ACCEPT
#ntp date
iptables -A OUTPUT -p udp --dport 123 -j ACCEPT
iptables -A INPUT -p udp --sport 123 -j ACCEPT
#apt get and wget
iptables -A OUTPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
#incoming ssh
iptables -A INPUT -i eth0 -p tcp --dport 50555 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 50555 -m state --state ESTABLISHED -j ACCEPT
#outgoing ssh
iptables -A OUTPUT -o eth0 -p tcp --dport 22 -d 192.168.178.0/24 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
#Allow Incoming HTTP and HTTPS
iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
#Allow Ping from Inside to Outside
iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
#Allow outgoing dns
iptables -A OUTPUT -p udp -o eth0 --dport 53 -j ACCEPT
iptables -A INPUT -p udp -i eth0 --sport 53 -j ACCEPT
#Logging
iptables -N LOGGING
iptables -A INPUT -j LOGGING
iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPTables Packet Dropped: " --log-level 7
iptables -A LOGGING -j DROP
|
Erase your rule number 5. It should be:
iptables -A INPUT -i eth0 -s 192.168.178.0/24 -p tcp --dport 445 -m state --state NEW,ESTABLISHED -j ACCEPT
And the related connection(new rule)
iptables -A OUTPUT -o eth0 -d 192.168.178.0/24 -p udp --sport 445 -m state --state ESTABLISHED -j ACCEPT
And, to avoid very long rule lists, you could set the default OUTPUT policy to ACCEPT so, you dont need to create a rule based on established sessions to every INPUT rule you have. After some time this will make you create rules faster.
It is somehow an overkill if you don´t have any service that can create excessive traffic output without you knowing. Or, create a specific rule to output related traffic:
iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT
| Firewalling Samba |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.