By Manny Fernandez

November 25, 2019

Fortinet FIT / Tinycore Linux Static IP addressing

Last night, I decided to deploy the Fortinet FIT OVA which is essentially a packet generator that pushes attacks, web categories and the like to a FortiAnalyzer to show customers.  I wanted to set a static IP as opposed to the dynamic IP it came with.  I put together a small article showing how to do this.  The way Tinycore works is based on a Live environment.  When you reboot, it will revert back by default.  There may be other ways of doing this but this is what worked for me with my situation.

Creating Internet Script

Here I will show you the basic file needed to assign a static IP address to the FIT OVA or Tinycore Linux installation.

cd /opt
vi eth0.sh

Above we can see that we are “changing directory” to /opt then issuing the vi command to load the text editor VI.  Once you are inside the vi editor, you can type the letter i to enter into edit mode.

#!/bin/sh


sleep 1
if [ -f /var/run/udhcpc.eth0.pid ]; then
kill `cat /var/run/udhcpc.eth0.pid`
sleep 0.1
fi


ifconfig eth0 10.1.106.54 netmask 255.255.255.0 broadcast 10.1.106.255
route add default gw 10.1.106.1
echo nameserver 10.1.106.43 >> /etc/resolv.conf

The first set of commands after sleep essentially kills the DHCP client from running. Next we assign the IP address, default gateway and DNS servers.

NOTE: You COULD type these commands at the command line, but upon rebooting, you would lose all configurations.

Make Script Executable

Next we are going make the file executable

sudo chmod +x /opt/eth0.sh

This command adds the “execute” or “x” privilege to the file making the file executable.

Persistence

Next we will make the configuration me made persistent by adding it to some default scripts.

echo ‘/opt/eth0.sh’ >> /opt/.filetool.lst
echo ‘/opt/eth0.sh &’ >> /opt/bootlocal.sh

The .filetool.lst contains files and folders to be backed up. The next command copies the interface script into the bootlocal.sh file which loads on boot every time.

The .filetool.lst tells Tinycore where to store files it backs up.  By default it is stored  in a folder under the /mnt point under a tce folder.

NOTE:  You should add the following paths to the backup:

/etc/passwd
/etc/group
/etc/shadow

2019-11-24_23-30-30.png

Above we can see the file and the path it stores it in.

mannyf@box:/opt$ cat /opt/bootlocal.sh
#!/bin/sh
# put other system startup commands here
etc/init.d/dropbear start
/opt/eth0.sh &

As you can see from the cat command, we see the /opt/eth0.sh script file has been added or appended to the bottom of the file. Since we used the >> it means to append.

Restart

Either run service network restart or reboot.

Now we will run the ifconfig command to see the results

mannyf@box:/opt$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:<REMOVED>
inet addr:10.1.106.54 Bcast:10.1.106.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2896 errors:2 dropped:309 overruns:0 frame:0
TX packets:378 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:449788 (439.2 KiB) TX bytes:35824 (34.9 KiB)
Interrupt:19 Base address:0x2000

Creating a User

To create a user in Tinycore, you will need to run the adduser command which is common in other Linux distros.

mannyf@box:~$ sudo adduser monkey
Password: <Enter your Sudo user password>
Changing password for monkey
New password: <Enter new password for user monkey>
Retype password: <Re-Enter the new password for user monkey>
Password for monkey changed by root

Sudoer

In order to add the user you just created to the sudoer list, you will need a special command.  Sudoers are allowed to issue the sudo command at the command line.

sudo visudo

Run the sudo visudo command and add the last line (with your user that you created under the Creating a User section).

#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL=(ALL) ALL
monkey ALL=(ALL) ALL

Testing Connectivity

Well if you can get to the ssh prompt you should be ok with the IP address.  But lets test by pinging 4.2.2.2

2019-11-24_23-48-18.png

Here we can see 0% packet loss.

Hope this helps

Recent posts