Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: static IP init script

  1. #1
    Join Date
    Apr 2013
    Location
    Modra, Slovakia
    Posts
    265

    Default static IP init script

    I'm trying to set up static IP command
    Code:
    ifconfig enp4s0 192.168.1.11 netmask 255.255.255.0 up
    and
    Code:
    ip route add default via 192.168.1.1
    works but wont survive reboot then I ccheked how to wirte init scripts and I came along with smth like this
    Code:
    #!/bin/bash
    
    ### BEGIN INIT INFO
    # Provides:             statip
    # Required-Start:       $local_fs $network $remote_fs
    # Required-Stop:        $null
    # Default-Start:        3 5
    # Default-Stop:         0 1 6
    # Short-Description:    your description
    # Description:          your description
    ### END INIT INFO
    
    # Path to executable
    statip=/bin/stat_IP               
    
    test -x "$statip" || exit 5
    
    
    # Include status script
    . /etc/rc.status
    rc_reset
    
    case "$1" in
            start)
            echo -n "Starting service statip"
            $statip   # tu zmena
            rc_status -v
            ;;
            stop)
            echo -n "Shutting down service statip"
            killproc -TERM  $statip
            rc_status -v
            ;;
            try-restart|condrestart)
            # Restart only if program is running
            $0 status
            if [ $? = 0 ]; then
                    $0 restart
            else
                    rc_reset
            fi
            rc_status
            ;;
            restart)
            $0 stop
            $0 start
            rc_status
            ;;
            reload|force-reload)
            echo -n "Reloading service statIP"
            killproc -HUP $statip
             rc_status -v
            ;;
            status)
            echo -n "Checking status of service statIP"
            checkproc $statip
            rc_status -v
            ;;
            *)
            echo "Usage: $0 {start|stop|restart|try-restart|condrestart|reload|force-reload|status}"
            exit 1
            ;;
    esac 
    rc_exit
    I put that ifconfig and ip command in that
    Code:
    /bin/stat_IP
    ANd my question is : is it correct and if just make symbolic link to that script in correscponding runlevel like ln -s /init.d/staticIP /init.d/rc3.d rename it to S30staticIP and S50staticIP in runlevel 3,5 for start script and for stop script in 0,1,6 K0staticIP .......

  2. #2
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: static IP init script

    On 2014-01-17 13:26, roberto68 wrote:
    >
    > I'm trying to set up static IP command
    > Code:
    > --------------------
    > ifconfig enp4s0 192.168.1.11 netmask 255.255.255.0 up
    > --------------------
    > and


    Why?
    Why not use the services the system already provides?


    > I put that *ifconfig* and *ip* command in that
    > Code:
    > --------------------
    > /bin/stat_IP
    > --------------------
    > ANd my question is : is it correct and if just make symbolic link to
    > that script in correscponding runlevel like ln -s /init.d/staticIP
    > /init.d/rc3.d rename it to S30staticIP and S50staticIP in runlevel 3,5
    > for start script and for stop script in 0,1,6 K0staticIP .......



    Will never work. Not with systemv, nor with systemd.
    Read the openSUSE documentation on how the boot process works.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 12.3 x86_64 "Dartmouth" at Telcontar)

  3. #3
    Join Date
    Apr 2013
    Location
    Modra, Slovakia
    Posts
    265

    Default Re: static IP init script

    because whne I swithc networking to ifup and turn of network manager and dhcp and configure /etc/sysconfig/network/enp4s0 ( is interface I'm connected to router thru) it says some dependecies problem and I found a thread in suseforums where other fella also stated this problem and seems like it's a bug (maybe solved since that)

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,810

    Default Re: static IP init script

    Yes, it does not survive a system shutdown, because it is in the kernel.

    Why not using YaST. That worked for me (and many. many others) without problems for many years. In fact YaST indeed puts this in files in /etc/sysconfig/network. But why not using YaST?
    Henk van Velden

  5. #5
    Join Date
    Apr 2013
    Location
    Modra, Slovakia
    Posts
    265

    Default Re: static IP init script

    and how to disable dhcp daemon, cause I've not found any decent answer nothing in /init.d and in sysconfig dont know what particular option it is. ANd funny thing is through generic mozilla no page is available, but through TOR's mozilla everything si OK ???? WTF is that

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

    Default Re: static IP init script

    That is also in YaST > Network devices > Network settings.

    Select the network device you want to configure and click Edfit. There you can choose between DHCP or Statically assigned IP address. They are mutualy exclusive of course. And when oyu choose Statically ..., you can fill in IP address and Subnet Mask and Hostname.

    It seems al rather logical and intuitive to me. What is your problem? I hope I do not have to copy all what is to be seen on that screen here in the post.
    Henk van Velden

  7. #7
    Join Date
    Apr 2013
    Location
    Modra, Slovakia
    Posts
    265

    Default Re: static IP init script

    I've figured that out I've not assigned DNS server. and my question is will Yast save those statci settings if I've to use dhcp sometimes and then turn on static IP whne I'm back home (I'm on laptop). and I mean like dhcp won't start at next boot, I want to turn dhcp daemon or yast will take care of that?

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,810

    Default Re: static IP init script

    What you configure in YaST is either stored directly in configuration files (like /etc/resolv.conf) or in files in /etc/sysconfig/network to be used when the network scripts run (usualy at boot).
    Henk van Velden

  9. #9
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    32,339
    Blog Entries
    15

    Default Re: static IP init script

    On Fri 17 Jan 2014 06:46:01 PM CST, roberto68 wrote:


    and how to disable dhcp daemon, cause I've not found any decent answer
    nothing in /init.d and in sysconfig dont know what particular option it
    is


    Hi
    Sysvinit is gone, it's using systemd now, so systemctl is your friend.
    But as Henk advised, YaST will do what is needed, including disabling
    dhcp. Don't forget to add the gateway address, dns and search.

    --
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    openSUSE 13.1 (Bottle) (x86_64) GNOME 3.10.2 Kernel 3.11.6-4-desktop
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!


  10. #10
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: static IP init script

    On 2014-01-17 20:36, roberto68 wrote:
    >
    > I've figured that out I've not assigned DNS server. and my question is
    > will Yast save those statci settings if I've to use dhcp sometimes and
    > then turn on static IP whne I'm back home (I'm on laptop). and I mean
    > like dhcp won't start at next boot, I want to turn dhcp daemon or yast
    > will take care of that?


    If you are using a laptop and changing network sites, it is best you use
    network manager instead. It is designed for that.

    To switch network types and configs using ifup, the traditional method
    was to use "scpm" - however, I tested it briefly under systemd and I
    think it is broken. Which is a real pity.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 12.3 x86_64 "Dartmouth" at Telcontar)

Page 1 of 2 12 LastLast

Posting Permissions

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