Visit Our UNIX and Linux User Community


Changing ip in a custom way


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Changing ip in a custom way
# 1  
Old 08-06-2009
Changing ip in a custom way

Hi.
I hope someone can help me. I have e very special question.
I have a Lunix server and I have installed Webmin on it. This way, I can create a login for an other user and give him restricted access to some custom commands I set up.
One of the commands i would like to setup, is for him to change the ip adress. With Webmin, I have the option to edit files en perform commands afterwards, so my first thought was to edit the ifcfg-eth'x' file (x because i have several network cards). But the file contains too much data, for I want him to only be able to change the IP-adress, Netmask and Gateway (of 1 of the cards).
Standard it looks something like this:

# Intel Corporation 80003ES2LAN Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
BROADCAST=192.168.101.255
IPADDR=192.168.101.91
IPV6INIT=no
IPV6_AUTOCONF=yes
NETMASK=255.255.255.0
NETWORK=192.168.101.0
ONBOOT=yes
GATEWAY=192.168.101.1
TYPE=Ethernet
PEERDNS=yes
USERCTL=no

when actually I would only need something like this:

IPADDR=192.168.101.91
NETMASK=255.255.255.0
GATEWAY=192.168.101.1

Is there a way to link the original file to a new file, and when they edit teh new file, because of the link the original file will also be edited (the identical lines as IPADDR etc), and after which i give the command to restart the network devices, which allows the user to change only the given data in that new file, and so make him activate these new settings.

I hope I was clear enough; I know its something strange, but i need it in a very specific service.

thanks in advance!
# 2  
Old 08-07-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

**************************************************

Maybe a solution via sudo for the needed commands can do.
But what "normal" user should be able to change IP-addresses? Smilie

Whatever - you could set up something like an "exchange" directory where the use has permissions to edit the file and via cron it will replace the original file which has been backed up before of course and then issue a network restart.
# 3  
Old 08-07-2009
First of all, sorry for the mess I might have made in the previous post (Newbie :s) and thanks for the reply!!

Quote:
Originally Posted by zaxxon
Maybe a solution via sudo for the needed commands can do.
But what "normal" user should be able to change IP-addresses? Smilie
This is going to be an ip video server, so you can understand the actual 'user' has to be able to change the ip address.

Quote:
Originally Posted by zaxxon
Whatever - you could set up something like an "exchange" directory where the use has permissions to edit the file and via cron it will replace the original file which has been backed up before of course and then issue a network restart.
Now this looks like something I have been looking for. How do I make such an 'exchange' directory? And how do I link the new file with the original file? (or some data in the new file)?

The main idea is I am and remain the root, but the user can control some settings and do some commands, without becoming root or even log in to linux.

Thanks in advance!
# 4  
Old 08-07-2009
You create a group for these users and assign them to it. You create a directory where the file to be changed is placed in, lets say
Code:
/usr/local/var/vid_ipconf.txt

which is a copy of your ip config file.
chgrp the directory and the file so that the group you created can access and write to both, the directory and the file.

As next write a small shell script, that does a copy of the original file that will be placed under /etc/network.... (whereever your original config file is placed) each time the script is run. So a simple
Code:
cp -p /etc/network/origfile /origfile.bk

will do maybe.
Next this script copies the file placed the exchange directory (/usr/local/var/vid_ipconf.txt) over the original config file (/etc/network/origfile) and you have to restart your network (?? /etc/init.d/network restart).

This script should be placed into the crontab of root so that it will be called every interval you configure.

I hope the picture got sharper Smilie

Make sure you try out before you do so not that you loose connect entirely. No idea if you are remote connected to that machine or can access it via keyboard and screen locally if something goes wrong.
# 5  
Old 08-07-2009
Thanks!!!

That looks great! I'm gonna try that, but it is going to be for monday.
I am locally connected to the server, so it's no problem if something should change.
I will let you know if it worked.

Thank you!
# 6  
Old 08-10-2009
I'm a bit lost...

i get the theoretical part of your explanation, but it's the practical part where it al goes wrong Smilie
I have made the new file. Created a user(group).
The little shell script that makes the backup, that's ok to.
But then I get stuck. How do i create the script that copies the lines in the new file over the lines in the old file, without copying the whole file (lines like it's mac address can not be changed)? And can you explain me the part about the contrab, cause that's something I never heard before.
Sorry to keep bothering you..
# 7  
Old 08-10-2009
Cron:
https://www.unix.com/answers-frequent...n-crontab.html

Changing parts of the file; note that I have put another IP address into the "change" file so you notice the difference:
Code:
$> cat orig
# Intel Corporation 80003ES2LAN Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
BROADCAST=192.168.101.255
IPADDR=192.168.101.91
IPV6INIT=no
IPV6_AUTOCONF=yes
NETMASK=255.255.255.0
NETWORK=192.168.101.0
ONBOOT=yes
GATEWAY=192.168.101.1
TYPE=Ethernet
PEERDNS=yes
USERCTL=no
$> cat change
IPADDR=192.168.101.33  <----------------- here is a different number so you notice the difference?!
NETMASK=255.255.255.0
GATEWAY=192.168.101.1
$> awk -F"=" 'NR == FNR {_[$1]=$0; next} _[$1] {print _[$1]; next} $0' change orig
# Intel Corporation 80003ES2LAN Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
BROADCAST=192.168.101.255
IPADDR=192.168.101.33
IPV6INIT=no
IPV6_AUTOCONF=yes
NETMASK=255.255.255.0
NETWORK=192.168.101.0
ONBOOT=yes
GATEWAY=192.168.101.1
TYPE=Ethernet
PEERDNS=yes
USERCTL=no

 

Previous Thread | Next Thread
Test Your Knowledge in Computers #768
Difficulty: Medium
Smart cache, developed by AMD, is a level 2 or level 3 caching method for multiple execution cores
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Custom Report

Hi All, Am getting the raw report from the source and need to prepare the custom report as per the requirement. Requirement keep getting change according to the need. Raw data is as below /* ----------------- test_job_hu ----------------- */ insert_job: test_job_hu job_type: CMD... (4 Replies)
Discussion started by: pradeep84in
4 Replies

2. Shell Programming and Scripting

Custom Shell

I have a jump off server, which grants SSH access to a few other servers. I would like to create a custom shell which can be assigned to specific user accounts which runs a menu script upon login, where they can select which server they want to jump too, however should they hit ctrl-c or any... (1 Reply)
Discussion started by: JayC89
1 Replies

3. Shell Programming and Scripting

custom command

hi I am trying to make my own commands in my linux.I thought a command for changing directories will be easy. I made a simple file amd made the entries #!/bin/bash cd /opt/mydir I then made the file executable and then moved it to /usr/bin. But when i type the script name nothing... (2 Replies)
Discussion started by: born
2 Replies

4. Shell Programming and Scripting

doing own custom parameters

I have an rsync command that I want to create a variable where user can change to customize the parameters. complete rsync command to run: $RSYNC -e 'ssh -ax -o ClearAllForwardings=yes' --log-file=$LOG_FILE --delete -avzcr -u --update $SRC_DIR $USER@$TRG_SRV:$TRG_DIR >> $LOG_FILE What I... (4 Replies)
Discussion started by: abubin
4 Replies

5. AIX

Custom AIX Prompt

In my .profile, my prompt is set like this: set -o vi PS1=`logname`@`hostname -s`:'$PWD>' Is there a way to show what the history number would be of the command I'm typing in the prompt? For example, I frequently run commands then run 'history' to pull up the history number of a command... (2 Replies)
Discussion started by: ptrotter
2 Replies

6. Shell Programming and Scripting

Custom auto-complete

Hello: I am using csh, and am a complete noob when it comes to shell scripting. I want the following: 1) Ignore case when doing auto-complete. 2) If there are multiple matches (example: I have files abc.txt abc.txt.1, abc.txt.2 and type abc<tab>), count the number of matches. If... (1 Reply)
Discussion started by: madiyaan
1 Replies

7. Shell Programming and Scripting

Custom PS command

(0 Replies)
Discussion started by: goldfish
0 Replies

8. Shell Programming and Scripting

Changing userID and Changing group and GID

Hello, I want to write a ksh script about changing UID and changing group with GID. There are multiple servers i want to perform that job. linux1 linux2 linux3 linux4 linux5 ...... . . . . . 1.) How can i enter "password" in script rather asking me? I was trying this... ssh... (2 Replies)
Discussion started by: deal732
2 Replies

9. UNIX for Dummies Questions & Answers

How to custom application name in `ps -ef`?

A program named /usr/bin/aa.sh, two parameters: 11, 22. after start it, the row in `ps -ef` is almost like the following: root 12198 10278 0.0 Nov 25 pts/3 0:00.23 /usr/bin/aa.sh 11 22 but I want to change "/usr/bin/aa.sh 11 22" to one rule string, such as: "AA_11_22", how to... (1 Reply)
Discussion started by: linkjack
1 Replies

10. UNIX for Dummies Questions & Answers

Custom ftp settings

On the standard ftp supplied with Solaris and HP-UX is there anyone that has been able to disable users from certain settings. i.e the put function. Our customer ftp's onto the unix host and gets files for extraction into a pc based spreadsheet. I want to stop them from being able to delete... (1 Reply)
Discussion started by: blp001
1 Replies

Featured Tech Videos