Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7809235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:22:06+00:00 2026-06-02T03:22:06+00:00

I am developing a Python script that tests one networking application. As part of

  • 0

I am developing a Python script that tests one networking application. As part of the test, it needs to move networking configuration (IP address, routes …) from one interface (physical interface) to another interface (bridge), and after the test is done, restore the system back to its original state. What is the most elegant approach to accomplish this in Python?

Some ideas I have thought about:

  1. To not unassign the IP address from physical interface during the test, so that routes are not lost. But this would mean that the same IP address would coexist on the bridge during the test. Would this be a problem on some particular Linux Kernels? Although, it seems to work just fine on my system…
  2. Assign the IP address to bridge and unassign from physical interface. Easy to implement in python, because this requires to do simple ifconfig calls and parsing. But if the default route was through the physical interface, then it would disappear at the same time, when I unassigned the IP address from physical interface.
  3. Parse the ip route ls output and move the routes together with the IP config. This seems the only reasonable approach, but would require quite a lot of coding.

  4. Maybe there is something more elegant? Like iptables-save eth0>eth0_conf, iptables-restore eth0_conf? Any other suggestions?

This test tool must be portable, and be able to run on different Linux Kernels.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:22:09+00:00Added an answer on June 2, 2026 at 3:22 am

    I would suggest the following approach:

    1. Ensure the bridge interface is down
    2. Configure the bridge interface
    3. Execute ifconfig eth0 down && ifconfig br0 up

    And to restore:

    1. Execute ifconfig br0 down && ifconfig eth0 up

    Now for the routes it depends on what kind of routes you have. If you defined static routes with explicit interfaces, your only choice seems to be parsing ip route ls and translating them to the new interface.

    You can also toy around with the order of the up & down commands as well as multiple routing tables:

    ip route add <whatever> table 2
    ip rule add from br0 table 2
    

    But this can get tricky, so my suggestion would be to stick to the simple solution, even if it includes some more coding.

    Here is another example from xend’s network-bridge script to achieve this:

    # Usage: transfer_addrs src dst
    # Copy all IP addresses (including aliases) from device $src to device $dst.
    transfer_addrs () {
        local src=$1
        local dst=$2
        # Don't bother if $dst already has IP addresses.
        if ip addr show dev ${dst} | egrep -q '^ *inet ' ; then
            return
        fi
        # Address lines start with 'inet' and have the device in them.
        # Replace 'inet' with 'ip addr add' and change the device name $src
        # to 'dev $src'.
        ip addr show dev ${src} | egrep '^ *inet ' | sed -e "
    s/inet/ip addr add/
    s@\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/[0-9]\+\)@\1@
    s/${src}/dev ${dst}/
    " | sh -e
        # Remove automatic routes on destination device
        ip route list | sed -ne "
    /dev ${dst}\( \|$\)/ {
      s/^/ip route del /
      p
    }" | sh -e
    }
    
    # Usage: transfer_routes src dst
    # Get all IP routes to device $src, delete them, and
    # add the same routes to device $dst.
    # The original routes have to be deleted, otherwise adding them
    # for $dst fails (duplicate routes).
    transfer_routes () {
        local src=$1
        local dst=$2
        # List all routes and grep the ones with $src in.
        # Stick 'ip route del' on the front to delete.
        # Change $src to $dst and use 'ip route add' to add.
        ip route list | sed -ne "
    /dev ${src}\( \|$\)/ {
      h
      s/^/ip route del /
      P
      g
      s/${src}/${dst}/
      s/^/ip route add /
      P
      d
    }" | sh -e
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a Java application that calls a python script behind the scene.
I am developing a Python script that uses xlrd to obtain data from xls
I'm developing a python application and have a question regarding coding it so that
I am developing a C++ application that needs to be multiple platform compatible (Windows/Linux)
I'm using Twitter API with PHP, developing sort of tests. Those test are one
I am developing a Python application where i need many times to check if
I am developing a GPL-licensed application in Python and need to know if the
I have a python app, that I'm developing. There is a need to use
I am developing a Math application which can be extended by writing python scripts.
im a novice into developing an application using backend as Python (2.5) and Qt(3)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.