Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

How to Enable IP Forwarding and Masquerading on CentOS 7

A practical CentOS 7 gateway guide covering persistent IPv4 forwarding, scoped iptables forwarding rules, POSTROUTING MASQUERADE, firewalld zones, verification, troubleshooting, and end-of-life cautions.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To turn a CentOS 7 machine into an IPv4 gateway, enable kernel forwarding, make that setting persistent, allow the intended traffic through the FORWARD chain, and masquerade packets as they leave the Internet-facing interface. The commands below use eth1 for the internal network and eth0 for the external network; replace both names with the interfaces that actually exist on your server. CentOS 7 is end-of-life, so use this as legacy-platform guidance while planning migration to a maintained release.

What you are configuring

A gateway has at least two network interfaces. Clients on a private LAN send packets to the CentOS host, which routes them out through an external interface. Three independent controls must agree:

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Kernel forwarding: the Linux IPv4 stack must be allowed to pass packets between interfaces.
  • Firewall forwarding: the active firewall must permit the specific traffic in the FORWARD chain or through its zone policy.
  • NAT masquerading: packets leaving the external interface need their private source address rewritten to the gateway’s outward-facing address.

Enabling only one or two of these controls does not create a working gateway. Forwarding is disabled by default, and firewall policy can still reject packets after the kernel has been instructed to route them.

Check the topology before changing anything

The example names eth0 and eth1 are placeholders. CentOS 7 installations may use predictable names such as enp0s3 or ens33. Identify the real interfaces and routes first.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
  1. List interfaces and their addresses:
    ip -br address
  2. Display the routing table and default route:
    ip route
  3. Confirm which interface owns the default route. That is normally the external interface used with -o in the NAT rule.
  4. Identify the internal interface or interfaces and the client subnet they serve. For example, an internal network might be 192.168.10.0/24; use your actual subnet instead.
  5. Check which firewall service is active before choosing commands:
    systemctl is-active firewalld
    systemctl is-active iptables

Run configuration commands as root or through sudo. Record the current firewall rules and sysctl value so you can compare them after the change or roll back deliberately.

Enable IPv4 forwarding immediately

Set the running kernel value with:

sysctl -w net.ipv4.ip_forward=1

The Linux kernel documents net.ipv4.ip_forward as the boolean that forwards packets between interfaces: 0 disables forwarding and 1 enables it. The documented default is 0.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Verify the live value:

sysctl net.ipv4.ip_forward
cat /proc/sys/net/ipv4/ip_forward

Both checks should report 1. This change affects the running system only; a reboot or a later sysctl reload can return it to the configured default unless you persist it in a configuration file.

Make forwarding survive a reboot

Edit /etc/sysctl.conf and add or change this line:

net.ipv4.ip_forward = 1

Then load the file immediately:

sysctl -p /etc/sysctl.conf

sysctl -p is equivalent when the default file is being used. The command prints the values it loads; check that the forwarding assignment is accepted, then confirm with sysctl net.ipv4.ip_forward.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

On systems managed with drop-in files, the same setting can be kept in a file under /etc/sysctl.d/ instead of the main file. Use one deliberate source of truth, document it for the next administrator, and reload the file you changed. A persistent setting controls the kernel; it does not by itself open the firewall or add NAT.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Allow forwarding with iptables

If the host uses direct iptables administration, add rules to the filter table’s FORWARD chain. Red Hat’s basic pattern accepts traffic entering from the internal interface and leaving through it on the return path:

iptables -A FORWARD -i eth1 -j ACCEPT
iptables -A FORWARD -o eth1 -j ACCEPT

Replace eth1 with the internal interface. These broad rules are easy to understand but may permit more traffic than your gateway should carry. They also assume that the rest of your policy is appropriate. Review the current chain first:

iptables -L FORWARD -v -n --line-numbers

Use a narrower policy when the gateway has a defined LAN

For a single private subnet, constrain forwarding by interface, source network, destination interface, and connection state. The following pattern allows new connections from the LAN to the external interface and permits replies belonging to established connections:

iptables -A FORWARD -i eth1 -o eth0 -s 192.168.10.0/24 -m conntrack --ctstate NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -d 192.168.10.0/24 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

Change the subnet and interfaces to match your topology. If you have multiple internal interfaces, create a rule for each intended path rather than accepting every interface indiscriminately. If the chain has an earlier DROP or REJECT, rules appended with -A may never be reached; insert or reorder rules only after examining the existing policy and your change-control requirements.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Do not confuse forwarding with local traffic

The FORWARD chain handles packets routed through the machine. Rules in INPUT and OUTPUT govern traffic addressed to, or generated by, the gateway itself. Opening an SSH or web service on the gateway does not enable transit traffic, and enabling transit traffic does not automatically expose a service listening on the gateway.

Add IPv4 masquerading on the external interface

Append a NAT rule to the POSTROUTING chain:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Replace eth0 with the real outward-facing interface. The command components mean:

Part Purpose
-t nat Selects the NAT table.
-A POSTROUTING Appends a rule that runs after the routing decision, as packets are about to leave.
-o eth0 Matches packets whose output interface is the external interface.
-j MASQUERADE Rewrites the private source address to the gateway’s address on that external interface.

Masquerading is what lets private client addresses communicate with public networks while presenting the gateway’s outward-facing address. It does not decide whether forwarding is allowed; the filter rules still have to accept the traffic.

Inspect the loaded NAT rule and its packet counters:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
iptables -t nat -L POSTROUTING -v -n --line-numbers

Persist the firewall policy

Unlike the sysctl value in /etc/sysctl.conf, an iptables rule added at the command line is a running-kernel rule. Plan how your CentOS 7 host restores firewall policy after a reboot. On an iptables-managed installation, the traditional CentOS service workflow is:

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
service iptables save

That saves the currently loaded rules in the service’s configuration location. Confirm that your host actually uses the iptables service and that your change-management process permits this operation. If another firewall manager restores rules at boot, use that manager’s persistence mechanism instead of maintaining two independent copies.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Firewalld-managed hosts: use zones, not parallel iptables administration

CentOS 7 commonly runs firewalld rather than a hand-maintained iptables service. Check with systemctl is-active firewalld. When firewalld is active, make the forwarding sysctl persistent as a drop-in under /etc/sysctl.d/ (or in /etc/sysctl.conf), reload the sysctl configuration, and express interface and NAT policy through firewalld zones.

Assign the internal and external interfaces to the appropriate zones, then enable masquerading on the external zone. A typical command shape is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
firewall-cmd --permanent --zone=internal --add-interface=eth1
firewall-cmd --permanent --zone=external --add-interface=eth0
firewall-cmd --permanent --zone=external --add-masquerade
firewall-cmd --reload

Use the zones and interface names that match your design. Zone assignment alone is not a substitute for a forwarding policy: ensure the active zone configuration permits the intended inter-interface traffic, and limit sources and destinations where your policy requires it. Inspect the result with:

firewall-cmd --get-active-zones
firewall-cmd --zone=external --query-masquerade
firewall-cmd --zone=external --list-all
firewall-cmd --zone=internal --list-all

Do not independently append unmanaged iptables rules while firewalld is controlling the host. Choose one policy owner, because competing services can overwrite rules, produce misleading tests, or leave NAT and forwarding inconsistent after a reload.

Verify the gateway in three layers

1. Confirm the kernel switch

sysctl net.ipv4.ip_forward

The result must be net.ipv4.ip_forward = 1. If it is 0, reload the file containing the setting and look for syntax errors or a later configuration file overriding it.

2. Confirm filter and NAT rules

For iptables, check both the forwarding chain and the NAT chain:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
iptables -L FORWARD -v -n --line-numbers
iptables -t nat -L POSTROUTING -v -n --line-numbers

Packet and byte counters should increase when an allowed client generates traffic. A zero counter usually means the packet is taking a different interface path, is being rejected earlier, or the client is not using this machine as its gateway.

3. Test from an actual client

Configure a permitted LAN client to use the CentOS host as its default gateway, then test a destination outside the private network. Test an IP address first to separate routing and NAT problems from DNS problems. Repeat while watching the firewall counters. If the client can reach the gateway but not an external address, inspect the FORWARD policy and masquerade rule; if counters remain at zero, revisit interface names, routes, and the client’s default gateway.

Troubleshoot common failures

Symptom Likely cause What to check
Forwarding value is 0 The setting was applied only temporarily, the wrong file was edited, or another sysctl file overrides it. Run sysctl -p /etc/sysctl.conf, inspect the exact file containing net.ipv4.ip_forward = 1, and verify again.
Client reaches the gateway but not the Internet FORWARD traffic is blocked or the NAT rule uses the wrong output interface. Inspect iptables -L FORWARD -v -n, ip route, and iptables -t nat -L POSTROUTING -v -n.
NAT counters stay at zero The rule’s -o interface does not match the route actually used. Compare the default route’s device with the interface named after -o.
Only some connections work Rules are too broad in one direction, omit return traffic, or are shadowed by an earlier rule. Review rule order and connection-state matches; permit established and related replies on the return path.
Rules disappear after reboot or reload Runtime iptables commands were never saved, or firewalld replaced unmanaged rules. Identify the active firewall service and persist policy through that service only.
Firewalld commands appear ineffective The interface is in an unexpected zone or the zone policy does not allow forwarding. Run firewall-cmd --get-active-zones, inspect each zone, and correct assignments and forwarding policy.

Limit the gateway to the traffic you intend to route

  • Prefer interface and source-subnet matches over an unrestricted FORWARD accept rule.
  • Allow return traffic with connection-state rules rather than opening every direction equally.
  • Use the actual external interface in the MASQUERADE rule; do not leave the example name unchanged.
  • Review counters after deployment and during incident response. They show whether packets reached the rule, not whether the remote service replied.
  • Document the internal subnet, interface roles, firewall owner, sysctl file, and rollback procedure.

To remove a test iptables rule, repeat its command with -D instead of -A, or delete it by the line number shown by --line-numbers. Remove the corresponding NAT rule separately; filter and NAT tables are independent.

CentOS 7 lifecycle consideration

CentOS 7 is end-of-life. It no longer receives the normal maintenance and security coverage expected of a supported server platform. Keep any remaining gateway tightly controlled, record the legacy configuration, and plan a migration to a maintained distribution. Recreate and test the forwarding, firewall, and NAT policy on the target system rather than assuming that interface names, firewall defaults, or service ownership will be identical.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick deployment checklist

  1. Identify the internal and external interfaces with ip -br address and ip route.
  2. Check whether iptables or firewalld owns the firewall.
  3. Run sysctl -w net.ipv4.ip_forward=1.
  4. Set net.ipv4.ip_forward = 1 in /etc/sysctl.conf or a documented /etc/sysctl.d/ drop-in, then reload it.
  5. Permit only the required internal-to-external and established return traffic.
  6. Add MASQUERADE to POSTROUTING on the real external interface, or enable masquerading in the external firewalld zone.
  7. Persist the policy through the firewall service that is actually active.
  8. Verify sysctl output, rule counters, and an end-to-end test from an authorized client.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.