How to Open Ports in Linux Server Firewall

SSH into your server as Root: ~ >>; , Get to the directory where the configuration file is for CSF: ~ >> cd /etc/csf Press (Enter) Note: This is where CSF keeps all of its files, not just the configuration file. , Open the configuration file so that...

21 Steps 2 min read Advanced

Step-by-Step Guide

  1. Step 1: SSH into your server as Root: ~ >>;

    Something like "Vim" editor is good because it's nice and easy.

    If you use a different editor that is fine, just know that the commands showing are for "Vim." csf >> vim csf.conf Press (Enter) Note:
    This file has a lot of great security settings in it that you can tweak to your needs, but I am not going to be going into those here.

    You can read the comments in the file and they do a great job of explaining what each setting does.

    Once you have the file open, you will see a "TCP_IN" and "TCP_OUT" section.

    It will look like this: ,, Yours may look different so don't panic! It all depends on your configuration. , This is where we are going to add our port. 2095, 2096, 8000[]"   Since we are using "Vim" we need some special commands.

    Press the on your keyboard.

    This will allow you to enter "Vims"
    -
    - insert
    -
    - mode so you can add text. ,, This will get you out of
    -
    -insert-
    - mode. , Hold the (Shift) key and press ( ; ).

    At the bottom, ( : ) should appear with a blinking cursor. , This stands for
    -write and
    -quit. , csf >> service csf restart Press (Enter) You will see this: ,, Don't Worry! These are all IPs that have either been blacklisted or whitelisted and are being put back into the firewall.

    This will only take like five seconds (unless you have a huge list). ,
  2. Step 2: Get to the directory where the configuration file is for CSF: ~ >> cd /etc/csf Press (Enter) Note: This is where CSF keeps all of its files

  3. Step 3: not just the configuration file.

  4. Step 4: Open the configuration file so that we can edit it.

  5. Step 5: Allow incoming TCP ports TCP_IN = "20

  6. Step 6: 8000"  

  7. Step 7: Allow outgoing TCP ports TCP_OUT = "20

  8. Step 8: 8000" All those numbers there are ports that are currently "open".

  9. Step 9: Navigate down to the end of those lines after where you see that 8000 number.

  10. Step 10: Type in the port number:  2095

  11. Step 11: 8001[]" Do this for the TCP_OUT as well.

  12. Step 12: When you are finished

  13. Step 13: hold the (Ctrl) key on your keyboard and press the bracket button ( [ ).

  14. Step 14: Save and get out of this file.

  15. Step 15: Type the letters (w) and (q)

  16. Step 16: with no spaces.

  17. Step 17: Restart the firewall so that your changes take effect!

  18. Step 18: Stopping CSF

  19. Step 19: Then you will see (if any were in the blacklist or whitelist) a bunch of IPs flying across your screen.

  20. Step 20: When you see this

  21. Step 21: You are Done!

Detailed Guide

Something like "Vim" editor is good because it's nice and easy.

If you use a different editor that is fine, just know that the commands showing are for "Vim." csf >> vim csf.conf Press (Enter) Note:
This file has a lot of great security settings in it that you can tweak to your needs, but I am not going to be going into those here.

You can read the comments in the file and they do a great job of explaining what each setting does.

Once you have the file open, you will see a "TCP_IN" and "TCP_OUT" section.

It will look like this: ,, Yours may look different so don't panic! It all depends on your configuration. , This is where we are going to add our port. 2095, 2096, 8000[]"   Since we are using "Vim" we need some special commands.

Press the on your keyboard.

This will allow you to enter "Vims"
-
- insert
-
- mode so you can add text. ,, This will get you out of
-
-insert-
- mode. , Hold the (Shift) key and press ( ; ).

At the bottom, ( : ) should appear with a blinking cursor. , This stands for
-write and
-quit. , csf >> service csf restart Press (Enter) You will see this: ,, Don't Worry! These are all IPs that have either been blacklisted or whitelisted and are being put back into the firewall.

This will only take like five seconds (unless you have a huge list). ,

About the Author

S

Stephanie Hill

Writer and educator with a focus on practical lifestyle knowledge.

71 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: