Tiny Core Linux

General TC => Programming & Scripting - Unofficial => Topic started by: krlosg7 on November 06, 2015, 01:51:56 AM

Title: ip static for mac add in bootlocal.sh
Post by: krlosg7 on November 06, 2015, 01:51:56 AM
Hi all,

I have write a small script that allows every tinyvcore to start up with an IP static. To have this IP address the script must read mac address machine after boot.

the script is in /opt/script.sh and  in my /opt/bootlocal.sh, I have this entry: /opt/script.sh &

Here is the script.

Code: [Select]
#!/bin/sh
pkill udhcpc
case 'cat /sys/class/net/eth0/address' in
52:54:00:12:34:56) IP='ifconfig eth0 192.168.1.1 netmask 255.255.255.0 up' ;;
52:54:00:12:34:57) IP='ifconfig eth0 192.168.1.2 netmask 255.255.255.0 up' ;;
52:54:00:12:34:58) IP='ifconfig eth0 192.168.1.3 netmask 255.255.255.0 up' ;;
52:54:00:12:34:59) IP='ifconfig eth0 192.168.1.4 netmask 255.255.255.0 up' ;;
*) IP='ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up' ;;
esac
$IP

I reboot the machines. always every machine take the last IP.... how i can to fix it?

Any recommendation very welcome, Thanks in advance
Title: Re: ip static for mac add in bootlocal.sh
Post by: Misalf on November 06, 2015, 02:27:12 AM
You're using single quotes. That doesn't work as it's handled as a string. Use backticks instead.
Change this
Code: [Select]
case 'cat /sys/class/net/eth0/address' in
to this
Code: [Select]
case `cat /sys/class/net/eth0/address` in
or
Code: [Select]
case $(cat /sys/class/net/eth0/address) in
so it's interpreted as a command.
Title: Re: ip static for mac add in bootlocal.sh
Post by: gerald_clark on November 06, 2015, 05:44:18 AM
Why don't you just use dhcp and make the assignments in your dhcp server/router?
Title: Re: ip static for mac add in bootlocal.sh
Post by: Rich on November 06, 2015, 06:36:41 AM
Hi krlosg7
You might also want to consider simplifying that code snippet to something like:
Code: [Select]
#!/bin/sh
pkill udhcpc
case `cat /sys/class/net/eth0/address` in
52:54:00:12:34:56) SUBNET=1 ;;
52:54:00:12:34:57) SUBNET=2 ;;
52:54:00:12:34:58) SUBNET=3 ;;
52:54:00:12:34:59) SUBNET=4 ;;
*) SUBNET=5 ;;
esac
ifconfig eth0 192.168.1.$SUBNET netmask 255.255.255.0 up
Now the  case  statement is less busy and the intent is easier to follow.
Title: Re: ip static for mac add in bootlocal.sh
Post by: krlosg7 on November 06, 2015, 01:51:46 PM
 the answer by Misalf and Rich work  ;D.

gerald_clark talk about dhcp server but i have tried and that not work.

this is my topology.

multiple tap interface...

Code: [Select]
tap1: 10.10.10.1 /24
--------------------\            \
                     \------------\-------qemu server-----------ISC DHCP server
                     / 10.10.10.252/       10.10.10.253       10.10.10.254                           
--------------------/  OVS       /            eth1                 eth1
tap2: 10.10.10.2 /24

I've been trying to get dhcp address by an ISC Server. I have one DHCP Server and one qemu server with multiple image tiny core.

Over the qemu server OVS switch connects tap interfaces.

Any help would be appreciated with  dhcp server/router idea of  gerald_clark. Thanks.
Title: Re: ip static for mac add in bootlocal.sh
Post by: gerald_clark on November 06, 2015, 08:20:40 PM
Make sure you use a bridged connection in your virtual machine setup.