Results 1 to 8 of 8

Thread: Interface configuration via command line / script

  1. #1

    Default Interface configuration via command line / script

    Hello! I am fairly new to the Linux world, and I've been mainly using openSUSE since I started out. It's what I'm most familiar and comfortable with.


    I know that to set a static address without using the interactive yast, you need to edit (/etc/syconfig/network) ifcfg-eth0, routes and resolv.conf (+ /etc/hostname).


    How would I go about to configure this via commands, rather than manually editing files?
    Surely there's also a way to "find and replace" via some above-my-knowledge text manipulation tools like awk, but I'm hoping for a simpler solution I can implement into a script I'm working on (also bash scripting newbie).




    Cheers, K

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,738

    Default Re: Interface configuration via command line / script

    I do not quite understand your goal.

    You either know how it should be done "manually" (using a text editor), or you use a good system management tool and on openSUSE that is YaST.
    Henk van Velden

  3. #3

    Default Re: Interface configuration via command line / script

    Quote Originally Posted by hcvv View Post
    I do not quite understand your goal.

    You either know how it should be done "manually" (using a text editor), or you use a good system management tool and on openSUSE that is YaST.

    My goal is to set a static address on my system via a script I'm writing. Ergo I cannot manually edit files or use any interactive management tools like YaST.

  4. #4
    Join Date
    Mar 2011
    Location
    Sauerland
    Posts
    6,721

    Default AW: Interface configuration via command line / script

    Use Input/Output Redirection with > or >>

  5. #5

    Default Re: AW: Interface configuration via command line / script

    Quote Originally Posted by Sauerland View Post
    Use Input/Output Redirection with > or >>
    That would work, but not optimal having to echo out all these lines in the script.

    echo "BOOTPROTO='static'" > /etc/sysconfig/network/ifcfg-eth0
    echo "IPADDR='192.168.1.10'" >> /etc/sysconfig/network/ifcfg-eth0
    echo "MTU='1500'" >> /etc/sysconfig/network/ifcfg-eth0
    ...
    ...


    So what I take from the replies so far is that configuring the IP address via a one-liner is not something you generally do in SUSE.

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,738

    Default Re: AW: Interface configuration via command line / script

    Well, when you want to make your script as large as possible. This is more what I probably would do:
    Code:
    echo "BOOTPROTO='static'
    IPADDR='192.168.1.10'
    MTU='1500'
    ...
    ... " > /etc/sysconfig/network/ifcfg-eth0
    Quote Originally Posted by kaybeeoui View Post
    So what I take from the replies so far is that configuring the IP address via a one-liner is not something you generally do in SUSE.
    Well, when we prefer to use Wicked, we use YaST. Just once at installation (probably by doing it through the installer), and that is it.

    Maybe once in so many years you need to change your IP address, netmask, etc. and then we use YaST.

    Many people that have openSUSE on "walk around" devices (lap-tops and the like), use Network Manager.
    That is IMHO how it is "generally done on openSUSE" (not SUSE, or maybe it is also done on SUSE, but that is not subject op these forums).
    Henk van Velden

  7. #7
    Join Date
    Sep 2012
    Posts
    7,093

    Default Re: Interface configuration via command line / script

    Quote Originally Posted by kaybeeoui View Post
    My goal is to set a static address on my system via a script I'm writing.
    Script is just a tool to achieve some goal. You do not explain, why you need to use this script. So far it sounds like school homework assignment.

    Anyway - the tool to edit network configuration files is YaST. I am not aware of any other tool. It is trivial to write shell script to do it (it is less trivial to write good script with input check and error handling) but it hardly belongs to Network/Internet - ask in Programming section.

  8. #8

    Default Re: Interface configuration via command line / script

    The obvious alternative would be to use the 'ip' command with which you
    can add/remove IPs, add/remove routes, enable/disable network devices, etc.

    https://www.ghacks.net/2018/04/15/ba...for-beginners/

    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below.

    If you want to send me a private message, please let me know in the
    forum as I do not use the web interface often.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •