Setting up a Firewall on an s0.d1.small BMC Instance

Introduction

The s0.d1.small Bare Metal Cloud server instance is an affordable, single-CPU, general-purpose instance suitable for a broad array of workloads. One possible use case is using it for setting up a firewall to create a barrier for unwanted network traffic.

This tutorial shows how to set up a firewall on an s0.d1.small BMC server instance.

Setting up a firewall on an s0.d1. BMC instance.

Prerequisites

  • A Bare Metal Cloud (BMC) Portal account.
  • Access to the command line/terminal with administrator privileges.

How to Set Up a Firewall on the s0.d1.small BMC Instance?

Follow the steps outlined below to set up a firewall on your Bare Metal Cloud server instance.

Step 1: Deploy a s0.d1.small BMC Instance

1. Log in to the BMC portal with your phoenixNAP credentials. If you are a new client, create a Bare Metal Cloud account.

2. Follow the steps outlined in our tutorial for deploying a new Bare Metal Cloud server and get your server up and running in minutes.

  • Choose the s0.d1.small instance (the preselected option) in the server configuration step.
Choose the s0.d1.small BMC instance in the server configuration step.
  • Select the OS you want for your server and click Next. We’ve chosen Ubuntu Bionic for this tutorial as it is free, open-source, and deploys in around 60 seconds.
Choose which operating system you want to have on your BMC server.

3. Use SSH to connect to the new BMC server and set up a firewall.

Note: If you are new to SSH, read our tutorial to see how to use SSH to connect to a remote server in Linux or Windows.

Connect to the server via SSH using the allocated public IP address:

ssh [email protected][your public IP]
Use SSH to connect to the BMC server.

Step 2: Install a Firewall

After deploying the server and connecting to it, install a firewall on your Bare Metal Cloud server. Depending on your preferences, you can use several different firewall solutions, such as UFW or iptables.

For this tutorial, we will use the iptables firewall, which comes preinstalled in most Linux distros, and offers a variety of advanced settings.

You can run the install command to make sure the firewall is installed:

sudo apt-get install iptables
Install the iptables firewall on Linux.

Note: Install the persistent package to keep iptables firewall rules after rebooting the system. Run: sudo apt-get install iptables-persistent.

Since this BMC server has iptables already installed, the output shows the version.

Step 3: Set up the Firewall

After installing iptables, define rules for the firewall to improve your network security. Our ultimate iptables tutorial guides you through setting up each rule and appending it to the chain. Before defining the rules, all chains are set to ACCEPT. As a result, any packet can come through unfiltered.

Run the following command to view the current set of rules on your server:

sudo iptables -L
See the existing iptables rules.

The steps below show how to define some basic firewall rules and append them to the chain.

1. Define Rules

When you define a rule in iptables it means you are appending it to a chain. The syntax for defining new rules is:

sudo iptables -A [option]

The available options are:

  • -i (interface) – Specify a network interface whose traffic you want to filter (e.g., eth0, lo, ppp0, etc.).
  • -p (protocol) – Specify the network protocol you want to filter (e.g., TCP, UDP, ICMP, ICMPv6, etc.). Specifying all chooses every protocol.
  • -s (source) – Specify an address, hostname, or IP address for incoming traffic.
  • --dport (destination port) – Define the destination protocol port number (22 for SSH443 for HTTPS, etc.).
  • -j (target) – Specify the target name – ACCEPTDROPRETURN each time you make a new rule.

Using all the options requires the following order:

sudo iptables -A [chain] -i [interface] -p [protocol (tcp/udp) ] -s [source] --dport [port number]  -j [target]

In the following example, we have instructed iptables to keep the SSH connection working as usual and accept connections:

sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

The iptables firewall also allows you to filter connections based on an IP address or a range of IP addresses. For example, running the following command instructs iptables to accept connections from the specified IP address:

sudo iptables -A INPUT -s 87.116.140.66 -j ACCEPT

You can check if the rules have been appended by running:

sudo iptables -L -v
Check if the rules you defined have been defined.

2. Save Changes

To prevent losing your iptables rules after a reboot, make sure to save your changes by running:

sudo /sbin/iptables-save
Make iptables rules persist after reboot.

The output lists the rules and saves them.

3. Delete Rules

If you want to start over and define new rules, use the -F (flush) option:

sudo iptables -F

To delete a specific rule, you need to specify its line number. See all rule line numbers by running:

sudo iptables -L --line-numbers
See line numbers of existing iptables rules.

The output lists all the rules and states their line numbers. Now you can use the following syntax to delete a specific rule:

sudo iptables -D INPUT [rule line number]

For example:

Delete a specific rule in iptables.

The output shows that only rule number 1 remains after instructing iptables to delete rule number 2.

Why Set Up a Firewall on a s0.d1.small BMC Instance?

There are several benefits to setting up a firewall on a s0.d1.small BMC instance:

  • Low cost. The small BMC instance costs only $0.10/h, and it is well suited for a wide variety of workloads, including a firewall. Additionally, the s0 BMC server can also serve as a load balancer, distributing traffic across multiple servers.
  • Secure. Improving network security is essential for any business, and the small s0 BMC instance is perfect for setting up a firewall to increase your network infrastructure security. Each BMC server instance also comes with free 20 Gbps DDoS protection.
  • Automated. With 20 pre-configured and fine-tuned instances, you can have your server up and running in only a few clicks. Finish setting up your firewall in minutes, and you can focus on your business, which is now safe from network attacks.

Conclusion

By following this tutorial, you should know how to set up a firewall on an s0.d1.small Bare Metal Cloud instance easily and quickly. The small and cheap BMC instance acts as a shield, protecting your business from network threats.

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/223267.html

(0)
上一篇 2022年1月6日
下一篇 2022年1月6日

相关推荐

发表回复

登录后才能评论