Find the answer to your Linux question:
Results 1 to 4 of 4
I am sshing from a windows box to fedora. I am attempting to write a batch file in windows that will ask a few questions assign the variables etc etc. ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3

    SSH to change IP

    I am sshing from a windows box to fedora. I am attempting to write a batch file in windows that will ask a few questions assign the variables etc etc. The issue is when I am trying to change the ip address of a linux machine, permanently. The ips have to be static and can change every so often. So I can ssh into fedora no issues and I can use ifconfig to change temporarily, till restart. The script should be automated so use clicks it asks a few questions then poof ip is changed for good. I am at a loss of how to do this. I am reletively new at this.

    Is there a way to do it this way? or do I need to have a script in fedora that this file connects to and runs? can you pass variables this way? I hate to ask this but if that is the case how would you write it. thanks and i am sorry if this is not structured very well in thought.

  2. #2
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    instead of using ifconfig, simply edit the config file for the device, it will be in /etc/sysconfig/network-scripts and it will be called something like ifcfg-eth0, but that will depend on the device, you need to be root or have sudo privilege to change this file, then you can restart network with /sbin/service network restart (also requires root/sudo)

  3. #3
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3
    yea i know how to do this. but this script will go to an end user that doesnt. they need to be on a windows box click the go button it ask them a few questions then the script needs to do all the work. thanks though.

  4. #4
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3
    Would the code below work on Fedora as a shell script?


    #!/bin/sh

    #setting up variables
    ip=$1
    mask=$2
    gate=$3
    export ip
    export mask
    export gate

    #Modifying the ifcfg-eth0 file
    awk -v ip=$ip -v mask=$mask -v gate=$gate '/ONBOOT=yes/{
    print
    print "DEVICE=eth0"
    print "BOOTPROTO=static"
    print "IPADDR=" ip
    print "NETMASK=" mask
    print "GATEWAY=" gate
    next cd
    }1' /etc/sysconfig/network-scripts/ifcfg-eth0> /etc/sysconfig/network-scripts/temp1

    sed -e's/no/yes/' /etc/sysconfig/network-scripts/temp1 > /etc/sysconfig/network-scripts/temp2

    rm /etc/sysconfig/network-scripts/ifcfg-eth0
    mv /etc/sysconfig/network-scripts/temp2 ifcfg-eth0
    chmod 644 /etc/sysconfig/network-scripts/ifcfg-eth0
    rm /etc/sysconfig/network-scripts/temp1
    rm /etc/sysconfig/network-scripts/temp2

Posting Permissions

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