Ask Sawal

Discussion Forum
Notification Icon1
Write Answer Icon
Add Question Icon

Jem Wrottesley




Posted Questions


No Question(s) posted yet!

Posted Answers



Answer


UFW, or Uncomplicated Firewall, is a simplified firewall management interface that hides the complexity of lower-level packet filtering technologies such as iptables and nftables. If you’re looking to get started securing your network, and you’re not sure which tool to use, UFW may be the right choice for you.

This tutorial will show you how to set up a firewall with UFW on Ubuntu 20.04.

To follow this tutorial, you will need:

UFW is installed by default on Ubuntu. If it has been uninstalled for some reason, you can install it with sudo apt install ufw.

This tutorial is written with IPv4 in mind, but will work for IPv6 as well as long as you enable it. If your Ubuntu server has IPv6 enabled, ensure that UFW is configured to support IPv6 so that it will manage firewall rules for IPv6 in addition to IPv4. To do this, open the UFW configuration with nano or your favorite editor.

Then make sure the value of IPV6 is yes. It should look like this:

Save and close the file. Now, when UFW is enabled, it will be configured to write both IPv4 and IPv6 firewall rules. However, before enabling UFW, we will want to ensure that your firewall is configured to allow you to connect via SSH. Let’s start with setting the default policies.

If you’re just getting started with your firewall, the first rules to define are your default policies. These rules control how to handle traffic that does not explicitly match any other rules. By default, UFW is set to deny all incoming connections and allow all outgoing connections. This means anyone trying to reach your server would not be able to connect, while any application within the server would be able to reach the outside world.

Let’s set your UFW rules back to the defaults so we can be sure that you’ll be able to follow along with this tutorial. To set the defaults used by UFW, use these commands:

These commands set the defaults to deny incoming and allow outgoing connections. These firewall defaults alone might suffice for a personal computer, but servers typically need to respond to incoming requests from outside users. We’ll look into that next.

If we enabled our UFW firewall now, it would deny all incoming connections. This means that we will need to create rules that explicitly allow legitimate incoming connections — SSH or HTTP connections, for example — if we want our server to respond to those types of requests. If you’re using a cloud server, you will probably want to allow incoming SSH connections so you can connect to and manage your server.

To configure your server to allow incoming SSH connections, you can use this command:

This will create firewall rules that will allow all connections on port 22, which is the port that the SSH daemon listens on by default. UFW knows what port allow ssh means because it’s listed as a service in the /etc/services file.

However, we can actually write the equivalent rule by specifying the port instead of the service name. For example, this command works the same as the one above:

If you configured your SSH daemon to use a different port, you will have to specify the appropriate port. For example, if your SSH server is listening on port 2222, you can use this command to allow connections on that port:

Now that your firewall is configured to allow incoming SSH connections, we can enable it.

To enable UFW, use this command:

You will receive a warning that says the command may disrupt existing SSH connections. We already set up a firewall rule that allows SSH connections, so it should be fine to continue. Respond to the prompt with y and hit ENTER.

The firewall is now active. Run the sudo ufw status verbose command to see the rules that are set. The rest of this tutorial covers how to use UFW in more detail, like allowing or denying different kinds of connections.

At this point, you should allow all of the other connections that your server needs to respond to. The connections that you should allow depends on your specific needs. Luckily, you already know how to write rules that allow connections based on a service name or port; we already did this for SSH on port 22. You can also do this for:

There are several others ways to allow other connections, aside from specifying a port or known service.

You can specify port ranges with UFW. Some applications use multiple ports, instead of a single port.

For example, to allow X11 connections, which use ports 6000-6007, use these commands:

When specifying port ranges with UFW, you must specify the protocol (tcp or udp) that the rules should apply to. We haven’t mentioned this before because not specifying the protocol automatically allows both protocols, which is OK in most cases.

When working with UFW, you can also specify IP addresses. For example, if you want to allow connections from a specific IP address, such as a work or home IP address of 203.0.113.4, you need to specify from, then the IP address:

You can also specify a specific port that the IP address is allowed to connect to by adding to any port followed by the port number. For example, If you want to allow 203.0.113.4 to connect to port 22 (SSH), use this command:

If you want to allow a subnet of IP addresses, you can do so using CIDR notation to specify a netmask. For example, if you want to allow all of the IP addresses ranging from 203.0.113.1 to 203.0.113.254 you could use this command:

Likewise, you may also specify the destination port that the subnet 203.0.113.0/24 is allowed to connect to. Again, we’ll use port 22 (SSH) as an example:

If you want to create a firewall rule that only applies to a specific network interface, you can do so by specifying “allow in on” followed by the name of the network interface.

You may want to look up your network interfaces before continuing. To do so, use this command:

The highlighted output indicates the network interface names. They are typically named something like eth0 or enp3s2.

So, if your server has a public network interface called eth0, you could allow HTTP traffic (port 80) to it with this command:

Doing so would allow your server to receive HTTP requests from the public internet.

Or, if you want your MySQL database server (port 3306) to listen for connections on the private network interface eth1, for example, you could use this command:

This would allow other servers on your private network to connect to your MySQL database.

If you haven’t changed the default policy for incoming connections, UFW is configured to deny all incoming connections. Generally, this simplifies the process of creating a secure firewall policy by requiring you to create rules that explicitly allow specific ports and IP addresses through.

However, sometimes you will want to deny specific connections based on the source IP address or subnet, perhaps because you know that your server is being attacked from there. Also, if you want to change your default incoming policy to allow (which is not recommended), you would need to create deny rules for any services or IP addresses that you don’t want to allow connections for.

To write deny rules, you can use the commands described above, replacing allow with deny.

For example, to deny HTTP connections, you could use this command:

Or if you want to deny all connections from 203.0.113.4 you could use this command:

Now let’s take a look at how to delete rules.

Knowing how to delete firewall rules is just as important as knowing how to create them. There are two different ways to specify which rules to delete: by rule number or by the actual rule (similar to how the rules were specified when they were created). We’ll start with the delete by rule number method because it is easier.

If you’re using the rule number to delete firewall rules, the first thing you’ll want to do is get a list of your firewall rules. The UFW status command has an option to display numbers next to each rule, as demonstrated here:

If we decide that we want to delete rule 2, the one that allows port 80 (HTTP) connections, we can specify it in a UFW delete command like this:

This would show a confirmation prompt then delete rule 2, which allows HTTP connections. Note that if you have IPv6 enabled, you would want to delete the corresponding IPv6 rule as well.

The alternative to rule numbers is to specify the actual rule to delete. For example, if you want to remove the allow http rule, you could write it like this:

You could also specify the rule by allow 80, instead of by service name:

This method will delete both IPv4 and IPv6 rules, if they exist.

At any time, you can check the status of UFW with this command:

If UFW is disabled, which it is by default, you’ll see something like this:

If UFW is active, which it should be if you followed Step 3, the output will say that it’s active and it will list any rules that are set. For example, if the firewall is set to allow SSH (port 22) connections from anywhere, the output might look something like this:

Use the status command if you want to check how UFW has configured the firewall.

If you decide you don’t want to use UFW, you can disable it with this command:

Any rules that you created with UFW will no longer be active. You can always run sudo ufw enable if you need to activate it later.

If you already have UFW rules configured but you decide that you want to start over, you can use the reset command:

This will disable UFW and delete any rules that were previously defined. Keep in mind that the default policies won’t change to their original settings, if you modified them at any point. This should give you a fresh start with UFW.

Your firewall is now configured to allow (at least) SSH connections. Be sure to allow any other incoming connections that your server needs, while limiting any unnecessary connections, so your server will be functional and secure.


Answer is posted for the following question.

How to set ufw active?

Answer


VEGA , otherwise known as The Father, is a minor, but very pivotal supporting character in Doom, namely in DOOM (2016), DOOM Eternal, and its DLCs. He is an ancient entity, true name unknown, created by Davoth, the first being in the multiverse, and was later reconstructed as an AI program.


Answer is posted for the following question.

What is vega in doom?

Answer


The phrase dictionary category 'Travel| Flirting ' includes English- Greek translations of common phrases and expressions


Answer is posted for the following question.

How to flirt in greek?

Answer


The leading experts in bad credit car finance Everyone considered 2 Minute online application, same day approval! Part exchange welcome and a great choice


Answer is posted for the following question.

Pay as you go car finance autozone?

Answer


Ranking of top private schools in Alabama based on academics, test scores, and private school ratings Compare top private schools near you


Answer is posted for the following question.

Coud you guide best private elementary schools in Alabama?

Answer


Our Top 16 Best Hair Salon In Delaware are : New Trend Hair Salon 45 stars from 195 Many regular customers return to see Todd himself


Answer is posted for the following question.

Do you know best hair salons in Delaware?

Answer


Best Student Loans For Bad Credit ; Federal Direct Subsidized Loans 50 · N/A · 373% ; Federal Direct Unsubsidized Loans 50 · N/A · 373% or 528%


Answer is posted for the following question.

Where can i get a student loan with bad credit?

Answer


Leggings cling close to the skin and don't do anything to hide underwear lines (with some exceptions depending on the material, color, and pattern), hence why


Answer is posted for the following question.

Why can't i wear leggings to school?

Answer


What makes alcoholics drink ? New research has found that in both men and women with alcohol dependence, the major factor predicting the


Answer is posted for the following question.

Why do alcoholics drink?

Answer


Hey sorry @danielgatis and @suri199507, latest events got me quite busy

First of all, I'm a newbie to python and machine learning and stuff, I'm just crawling the web for information I can use to achieve some specific background/object removal tasks. So please don't judge this non professional response 😅

The U²Net-Repository was originally trained on the DUTS-TR dataset which is a set of imagery and their counterpart masks. So you have images like

DUTS-TR/DUTS-TR-Image/ILSVRC2012_test_00000022.jpg

and their couterpart mask DUTS-TR/DUTS-TR-Mask/ILSVRC2012_test_00000022.png

which is according to the resources I found the ground truth binary mask (i guess this means only black and white) of what element of the image should be segmentated.

So at first, u need to create your own dataset like DUTS-TR and mask the objects you want to segmentate in white and leave the background / parts you want to be removed by RemBG black. By the way, RemBG does not only work for background removal, you can train a U²Net model to also segmentate a specific part of the image you want to be removed (leave it black in the mask and all the surroundings white. You can change this behavior, but by default you have one directory with the images (.jpg) and another directory containting only the masks (same name like it's original image but .png extension)

I cloned the U²Net-Repository and made a few changes in it's u2net_train.py-file (like changing the model name and directories for the train data because references to them were quiet hard coded). Because U²Net was originally trained with the DUTS-TR dataset, you'll need to change some file system references to your own dataset. Here an example out of u2net_train.py

If you change the model_name some other references won't work as well, so you need to make some adjustments like switching from

to

You will need to change some other parts I won't describe here e.g auto saving models, cuda support etc.. Crawl The U2net Issues for more information. If you (are different than me and you) know what you are doing, you can adjust the model parameters like the loss function in u2net_train.py or others in model\u2net.py. Anyways, I left them like they were and got nevertheless good results, although my dataset has nothing to do with "salient object detection".

After fixing all the errors occuring while executing python u2net_train.py (almost every error/warning was due to switching file system references/directories etc.), you can leave it running for some time (I trained my dataset almost 2 weeks to get satisfiable results). Your model/weights will be saved after a certain count of iterations which you can then use to test your weights on test images in u2net_test.py.

After that you convert it to .onnx like described before and it works wonderful with rembg.

To @suri199507

The script to convert the .pth-weights and model to onnx I posted before just sits in the same cloned repository of U²Net, so it imports the models out of model/u2net.py. As far as i know, pytorch needs this information besides the saved model weights (the .pth file) to interprete whats going on and process an .onnx based model.


Answer is posted for the following question.

How to convert pth to onnx?


Wait...