UFW can allow a chosen source address to reach a specific service on an Ubuntu host. A service-specific rule identifies the source, destination port, and protocol instead of allowing that address to every port. Before adding it, inspect the existing firewall policy and protect your management connection. A rule that is syntactically valid can still be too broad, ineffective because of another layer, or disruptive if the firewall is enabled remotely without an SSH path.

Check the actual service port on the server you administer. Identify the source address that reaches the Ubuntu host. A reverse proxy normally opens a separate connection, and source NAT can replace a client address, while ordinary routing does not itself require that replacement. Use the address visible at the host rather than assuming it is always the visitor's device address.

Read the Current Rules and Access Path

Run sudo ufw status verbose to check the current state and policy, then sudo ufw status numbered to see rules with their positions. Note whether UFW is active, the default incoming policy, existing allow and deny rules, and the port used for remote management. Save a copy of the current rule listing in the change record. If the server is managed through SSH, confirm that the intended UFW policy permits the actual SSH port from the administrator address or management network.

Enabling UFW can interrupt existing remote connections because the operation rebuilds its rule chains. Have a console or other recovery path when possible. An unrestricted allowance from one address can expose unrelated ports and services added later. A specific allowance also does not cancel broader permissions already in place: if another rule or the default policy admits everyone to the service, adding one source address will not exclude other clients. Review host, cloud, router, and container firewall layers separately; an allow rule on the Ubuntu host cannot override a block upstream.

Choose Source, Port, and Protocol

Use the extended rule syntax to specify the source and destination service. For a hypothetical TCP service on port 8443, preview the proposed change with sudo ufw --dry-run allow in proto tcp from 192.0.2.10 to any port 8443. The address 192.0.2.10 is reserved for documentation; replace it, the port, and the protocol with the values needed for your service. The in keyword makes the incoming direction explicit, and --dry-run displays the change without applying it.

The destination any covers the host's local addresses. Replace it with a particular local address when the permission should apply only there; an in on interface condition can narrow the rule further. Use a single host address instead of a larger subnet unless the whole subnet must be allowed.

Confirm whether the service uses TCP, UDP, or both; an allowance for one protocol does not automatically authorize the other. An IPv4 rule does not cover an IPv6 client. If the service is reachable over IPv6, review that family separately and check that UFW IPv6 support is enabled in /etc/default/ufw. An IPv6 allowance uses the same rule structure with the intended IPv6 source address.

Review the rule order before applying the allowance. UFW does not automatically prioritize a more specific rule over an earlier general rule; the first matching rule determines the action. If an earlier deny would catch the intended traffic, place the exception before that deny using the appropriate insert position rather than repeatedly appending allowances.

The numbered status list covers rules managed through the UFW command, not every underlying rule. Use sudo ufw show raw when the effective policy needs closer inspection, including rules evaluated before the user-added rules.

Apply the Rule and Check SSH Access

After checking the preview and rule order, apply the example with sudo ufw allow in proto tcp from 192.0.2.10 to any port 8443, using your real source address and service values. If the rule needs a different position, use the reviewed insertion point instead of appending this command.

If UFW is inactive, adding a rule stores the allowance but does not enable the firewall. Before running sudo ufw enable, add any missing management allowance for the actual SSH source and destination port, and arrange console access in case the remote session is interrupted. Do not assume SSH uses port 22 on your server. Keep the current session open while you verify a new SSH connection after the change.

Record a comment or change note explaining why the address was allowed and who requested the access. If the address comes from a cloud provider, office NAT, or VPN gateway, note that the address can change. Keep the service's authentication in place; a firewall allowance permits network traffic without verifying an application user's identity.

Verify Both Allowed and Disallowed Traffic

After the change, check UFW status and verify the rule appears with the intended source, protocol, and destination port. From the approved source, connect to the service and confirm the expected application response, not merely an open TCP port. From a different controlled source, verify access is still denied if that is the intended policy. Make fresh connections for these tests rather than relying on a session opened before the change.

If the permitted client cannot connect, inspect the host's sockets with sudo ss -lntup. Check the listening address and port as well as any upstream firewall or router forwarding. A service bound only to a loopback address will not become remotely reachable just because UFW allows a port. Compare the source address actually seen by the Ubuntu host with the one in the rule. For example, a reverse proxy may be the peer on the host connection. Resolve that mismatch before widening the rule.

For a Docker container with a published port, inspect the container networking rules as well. Published traffic can be diverted before the normal UFW host input rules, so a restrictive UFW status listing alone does not prove the container port is restricted.

Remove the Rule When It Is No Longer Needed

Review temporary allow rules after the task or incident ends. To remove the example, use sudo ufw delete allow in proto tcp from 192.0.2.10 to any port 8443 with the same values used when adding it. Alternatively, find its current number with sudo ufw status numbered and delete that number. Refresh the list after each deletion because the remaining numbers change.

Verify remote management access after cleanup and retest the affected service from both permitted and restricted sources. If a removed allowance appears to remain effective, check for another matching permission before changing the default policy.