AroundAround
Sign in Sign up
Menu
  • Home
    • Home
  • Blog
    Technology
    All Technology Software Engineering Web Applications Java Spring Framework Spring Boot AWS
    All Posts
    Smash Posts Transportation Posts Driving Posts Multi Location Post
    Transport
    Driving Articles Driving License Resources Refresh Drive Success Stories Special Articles
    Research
    Popular lists Weblogs Tutorials
    News
    Education Health Sports
    Traffic Signs
    Dubai Traffic Signs Qatar Traffic Signs Abu Dhabi Traffic Signs Saudi Arabia Traffic Signs Kuwait Traffic Signs Kerala Traffic Signs
  • Insights
    Interview Series
    All Interview Series Java Questions Spring Questions Microservices Questions Database Questions
    Lifestyle
    Umrah Articles Dubai UAE visa 180 days calculator Qatar residence visa 180 days calculator Prayer Time Malappuram Sqm to Cent calculator Kerala
    City Explorer
    Sulthan Bathery
  • Mock Tests
    Driving
    Test Home
    Dubai
    RTA Theory Test Parking Knowledge Test Deep-dive Assessment Test
    Abu Dhabi
    RTA Driving Theory Test Deep-dive Assessment Test Saudi Arabia Computer Test
    Other Regions
    Qatar Driving Theory Test Kuwait Driving Theory Test Ajman RTA Theory Test Sharjah RTA Theory Test Bahrain Driving Theory Test Learners License Test - Kerala
    Education
    Kindergarten School
  • Course & Videos
    • CoursesEnroll today
    • Videos20+Watch & Subscribe
  • Questions and Tags
    Topics
    Don't miss Million dollar questions Million Views Day to day life Interview Junky Trendy questions Theory wizard
    Technology
    Java Spring AWS
    Find the differences
    All Find the differences List
    Tags
    macOS AWS Spring
  • About Us
    • Privacy Policy
    • Contact
    • Terms & Conditions
    • Cancellation & Refund Policy
    • Shipping & Delivery Policy
  1. Home
  2. java
  3. Post

Closing a Specific Linux Port

Emma Brown
admin
#java #technology
Share post:
Share

Orphaned port? SSH connection down, but the port lingers. Learn how to reclaim that resource and prevent future port leaks. Click to see the solution!

How do I close a port on Ubuntu (e.g., after an SSH tunnel disconnects)?

Solution in a Nutshell

Closing specific ports on Linux for Java/Spring Boot apps usually involves system-level commands, not direct Java code. Spring Boot manages application ports, not system ports.

Method 1: Using iptables (requires root privileges)

sudo iptables -A INPUT -p tcp --dport 8080 -j DROP #Blocks incoming TCP traffic on port 8080
sudo iptables -A OUTPUT -p tcp --sport 8080 -j DROP #Blocks outgoing TCP traffic on port 8080
sudo iptables-save > /etc/iptables/rules.v4  #Save rules (persist across reboots)

Replace 8080 with your target port. -A INPUT appends to the INPUT chain; -j DROP drops the packets. -p tcp specifies TCP protocol. iptables-save persists changes. Always back up your iptables rules before making significant changes.

Method 2: Using ufw (Uncomplicated Firewall, user-friendly)

Simpler than iptables.

sudo ufw allow ssh #Allow SSH (important!)
sudo ufw deny 8080/tcp #Deny port 8080
sudo ufw enable #Enable firewall
sudo ufw status #Verify changes

ufw provides a user-friendly interface. Remember to allow necessary ports (e.g., SSH) before denying others.

Important Considerations:

  • Root privileges: Both methods require sudo (or root access).
  • Persistence: Saving rules (iptables-save or ufw enable) ensures changes persist after reboots.
  • Security: Incorrectly configuring firewalls can lock you out of your system. Proceed with caution and test thoroughly.
  • Spring Boot: Spring Boot's port configuration (server.port in application.properties/yml) only affects the application's internal port, not system-level port access.

This approach manages system-level port access, independent of your Java/Spring Boot application's port configuration. Always prioritize secure practices when managing system firewalls.

Sidebar

Search

Tags

#java #technology

Trending posts

Post

How to iterate through the HashMap in Java?

Post

How Can I convert a String to an int in Java?

Post

How to get a key from the value in Java HashMap

Post

In javascript how to replace all occurrences of a String?

  • Contact Us
  • Privacy Policy

© Copyright - smashplus 2013-25.