How can I overwrite the default gateway which radvd is advertising

2 min read 26-10-2024
How can I overwrite the default gateway which radvd is advertising

When working with network configurations, especially in environments that utilize IPv6, you may encounter scenarios where the Router Advertisement Daemon (radvd) is broadcasting a default gateway that doesn't meet your needs. Perhaps you need to route traffic through a different gateway, or you want to change the advertised prefix for a specific subnet. In this article, we will discuss how to overwrite the default gateway that radvd is advertising.

Original Problem Statement

The original problem can be stated as: "How can I overwrite the default gateway which radvd is advertising?"

Understanding radvd and Router Advertisements

The Router Advertisement Daemon (radvd) is a user-space daemon on Linux that helps manage IPv6 address autoconfiguration. It advertises available routers on the local network by sending Router Advertisement (RA) messages. These messages inform clients of their link-layer address, the prefix of the network, and the default gateway they should use.

Example of a Basic radvd Configuration

Before we get into the specifics of how to change the default gateway, let’s look at a simple example of what a radvd configuration file might look like:

interface eth0
{
    AdvSendAdvert on;
    AdvDefaultLifetime 30;
    prefix 2001:db8::/64
    {
        AdvOnLink on;
        AdvAutonomous on;
    };
    RDNSS 2001:db8:1::1
    {
        AdvRDNSSLifetime 30;
    };
};

In this example, radvd is configured to advertise the prefix 2001:db8::/64 on interface eth0 along with the associated router advertisement settings.

Overwriting the Default Gateway

To change the default gateway advertised by radvd, you need to edit your radvd configuration file. There are a couple of parameters you need to pay attention to:

  1. AdvDefaultLifetime - This parameter defines how long (in seconds) the router should be considered valid.
  2. AdvDefaultPreference - This parameter can be added to influence the preferred router when multiple routers are present.

Step-by-Step Guide to Overwriting the Default Gateway

  1. Open the Configuration File: Typically located at /etc/radvd.conf or a similar path.

  2. Edit the Configuration: Add or modify the following parameters as needed:

    interface eth0
    {
        AdvSendAdvert on;
        AdvDefaultLifetime 30;
        AdvDefaultPreference high;  # Setting preference to high
        prefix 2001:db8::/64
        {
            AdvOnLink on;
            AdvAutonomous on;
        };
        # Define the new default gateway
        route 2001:db8::/64
        {
            AdvRouteLifetime 30;
            AdvRoutePreference high;
        };
    };
    
  3. Restart the radvd Service: Once your changes are made, you need to restart the radvd service to apply the new configurations. Use the following command:

    sudo systemctl restart radvd
    

Verifying the Changes

To confirm that the new default gateway is being advertised, you can use the tcpdump command to capture and inspect Router Advertisement messages:

sudo tcpdump -i eth0 -n -vvv icmp6

Look for ICMPv6 messages showing the RAs and check the advertised default router.

Conclusion

Overwriting the default gateway advertised by radvd is a straightforward process once you understand the relevant configuration options. By modifying your radvd.conf file, you can effectively control which gateway is presented to clients on your network. This capability is particularly valuable in multi-router environments or when transitioning from one network configuration to another.

Additional Resources

By following the guidance provided in this article, network administrators can ensure they have full control over their router advertisements, enhancing the overall functionality and efficiency of their network environments.