Listing IPs from the dhcpd.conf


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing IPs from the dhcpd.conf
# 8  
Old 11-10-2017
Three comments first:
- use CODE not QUOTE tags for both code and data / output / errors.
- no caleidoscope (abundant colours) needed.
- ALWAYS add your environment info: OS, awk, etc. versions.

Your ^@ problem comes from the %c format specifier in the printf command. Replace by %s. My fault, sorry.
This User Gave Thanks to RudiC For This Post:
# 9  
Old 11-15-2017
Hy,

I'm still working on the same firewall :-)

I've got a file with such a following lines:
Code:
192.168.0.6     00:71:CC:6E:A3:33   
192.168.0.7     C0:38:96:72:8B:5B   
192.168.0.8     08:ED:B9:08:94:09   
192.168.0.9     D0:53:49:CB:FE:0F   
192.168.0.10    C4:8E:8F:8F:45:A7   
192.168.0.11     54:35:30:4E:01:8D   
192.168.0.12     DC:A9:71:9B:3C:AA   
192.168.0.13     D8:5D:E2:4E:F2:C5

How to revert them, i mean like this:
Code:
00:71:CC:6E:A3:33    192.168.0.6
C0:38:96:72:8B:5B     192.168.0.7
.......
.......

I've got gawk-3.1.7-10 and sed-4.2.1-10 in my OS

I have no idea of how to do it, so i'm sorry i can't give my own work!!

Thanks a lot.
# 10  
Old 11-15-2017
Code:
while read ip mac x; do
   echo $mac $ip
done < file

00:71:CC:6E:A3:33 192.168.0.6
C0:38:96:72:8B:5B 192.168.0.7
08:ED:B9:08:94:09 192.168.0.8
D0:53:49:CB:FE:0F 192.168.0.9
C4:8E:8F:8F:45:A7 192.168.0.10
54:35:30:4E:01:8D 192.168.0.11
DC:A9:71:9B:3C:AA 192.168.0.12
D8:5D:E2:4E:F2:C5 192.168.0.13

edit: I 'undeleted' my post because you referenced it two posts from now, but RudiC is right.. this should be done when producing the file. Sorry for butting in without reading the thread Smilie
# 11  
Old 11-15-2017
Why not just reverse the output fields when producing the file?
# 12  
Old 11-15-2017
RedHat

Thank you for the very quick reply Scott
It seem's so simple when we see the solution ......

Thanks again,

---------- Post updated at 10:45 AM ---------- Previous update was at 10:35 AM ----------

Quote:
Originally Posted by RudiC
Why not just reverse the output fields when producing the file?
Hello RudiC,

Well the file comes from your sed command:

Code:
sed -n '/^ *hardware ethernet/ {s///; h; d;}; /^ *fixed-address / {s///; G; s/[;\n]//g; s/ / -p tcp -m multiport --dports 110,143,25,465,585,993,995,80,443 -m mac --mac-source /; s/^/iptables -I FORWARD -s /; s/$/ -j ACCEPT/; p;}' /etc/dhcp/dhcpd.conf >> forward.sh

Then i flushed all the uneeded letters from the forward.sh file in order to get a file with these two rows (ip & MAC)

Thanks RudiC for your interest , appreciated :-)

Last edited by RudiC; 11-15-2017 at 12:31 PM.. Reason: Took out the diversity of font / format control statements.
# 13  
Old 11-15-2017
Well, I was afraid you did so: combining multiple "sub solutions" (small solutions to fulfill / resolve partial problems) collected when posting "sub questions" into an overly complex "general solution".

This is not what I imagined in post#6: one single command / script, be it sed or awk reading your dhcpd.conf once and outputting the rules file for your iptables

Take a step back and reconsider the overall problem, taking into account the basic input data and the required output. Methinks you've got everything at your fingertips from yout recent threads / posts.
# 14  
Old 11-15-2017
RedHat

Quote:
Originally Posted by RudiC
Well, I was afraid you did so: combining multiple "sub solutions" (small solutions to fulfill / resolve partial problems) collected when posting "sub questions" into an overly complex "general solution".

This is not what I imagined in post#6: one single command / script, be it sed or awk reading your dhcpd.conf once and outputting the rules file for your iptables

Take a step back and reconsider the overall problem, taking into account the basic input data and the required output. Methinks you've got everything at your fingertips from yout recent threads / posts.
LOL, actually I am using all the combined codes of all the previews posts for my firewall ;-) (your codes)

Now, this is different, i want to fill a file /etc/ethers with these two columns IP & MAC :-)

So the question : from where can i bring the IP's and the MAC adresses. That's why i said (dhcpd.conf) in this last post.

Code:
man ethers


Last edited by hermouche; 11-15-2017 at 02:01 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Changes in dhcpd.conf do not make a difference in DHCP service behaviour

Hi Experts, Our DHCP server currently answers the DHCP Discover requests from ServerX. In our dhcpd.conf file there are parameters defined for ServerX. Now we introduced some additional Servers into the network and want them to get service from the same DHCP server. Similar configuration... (13 Replies)
Discussion started by: ekorgur
13 Replies

2. Solaris

Configure resolv.conf and nsswitch.conf

Hi, I've installed Solaris 11.3(live media) and configured DNS. Everytime I reboot the server, resolv.conf got deleted and it created a new nsswitch.conf. I used below to configure both settings: # svccfg -s dns/client svc:/network/dns/client> setprop config/nameserver = (xx.xx.xx.aa... (1 Reply)
Discussion started by: flexihopper18
1 Replies

3. Shell Programming and Scripting

Script to update rsyslog.conf and auditd.conf

Hello all, Newbie here. I'm currently tasked with updating rsyslog.conf and auditd.conf on a large set of servers. I know the exact logging configurations that I want to enable. I have updated both files on on a server and hope to use the updated files as a template for the rest of the... (3 Replies)
Discussion started by: Mide
3 Replies

4. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

5. Shell Programming and Scripting

Help with Perl to change dhcpd.conf file

Hi all, I am too new for this stuff and i am lost in perl tutorials. I need help to change dhcp entries in .conf file with a perl script. The file entries are like below : host bertha-clp-0 { hardware ethernet AA:0A:A0:00:6c:40; fixed-address 10.10.10.72; option... (6 Replies)
Discussion started by: ekckabatop
6 Replies

6. Solaris

basic question on sd.conf and lpc.conf file

Hello Guys, Do we need to configure this file only if we add SAN disk or even if we add local disk, do we need to modify? (4 Replies)
Discussion started by: mokkan
4 Replies

7. UNIX for Advanced & Expert Users

Configuring snmpd.conf and snmptrapd.conf

HI, I want a help for Configuring snmpd.conf and snmptrapd.conf (i.e Configuring SNMP) for receiving TRAPS in my networks. I am using RHEL4.0 OS. Please tell me How I can configure above two files in a proper way and at an advanced level. Especially I am getting... (2 Replies)
Discussion started by: jagdish.machhi@
2 Replies

8. Linux

dhcpd.conf - static route

Hi, I've setup DHCP Server on RH linux AS3 and everything works fine except static routes. They are not getting effected on client systems. My dhcpd.conf: +++++++++++ ddns-update-style interim; ddns-updates off; option domain-name-servers 192.168.116.122; option domain-name... (3 Replies)
Discussion started by: prvnrk
3 Replies

9. Shell Programming and Scripting

Shell/Perl Script to edit dhcpd.conf

Hi, I need to get a script together to edit the dhcp service configuration file dhcpd.conf. Mac addresses are defined in classes ex. class "HOST1" { match if substring (hardware, 1,18)=00:11:11:FF:FF:FF;} class "HOST2" ... class "HOST3" ... ... followed by allow or deny statements:... (4 Replies)
Discussion started by: sahilb
4 Replies

10. Linux

dhcpd.conf

I have intall a REdhat 9.0 as a server and Ive configure to act as a DHCP however Im having technical problems b/c the file /etc/dhcpd.conf does not exists. I went to the text edit and I created : subnet 192.192.168.100.0 netmask 255.255.255.0 { range 192.168.100.10 192.168.100.150;... (1 Reply)
Discussion started by: keliy1
1 Replies
Login or Register to Ask a Question