Friday, December 6, 2013

Linux Immutable resolv.conf.

I often find that dhcp overwrites my resolv.conf not in the most optimal way. One example of this is when logging into more than one vpn tunnels that both set search domains. The simple answer to resolve this issue is to create the resolve.conf files and then set it as immutable.


Setup resov.conf:
/etc/resov.conf
options timeout:1 attempts:2
domain domain1.com domain2.net ... ... 
nameserver <work dns server>
nameserver <vpn dns server>
nameserver <home dns server>
nameserver 8.8.8.8 #googles dns server

Set /etc/resov.conf immutable:
#chattr +i /etc/resolv.conf


View files attributes:
$lsattr /etc/resolv.conf ----i--------e-- /etc/resolv.conf

The output shows that my resolv.conf file is set immutable (i) and and the it is on an ext4 filesystem (e).

To edit the file do the following:
#chattr -i /etc/resolv.conf


Side note about chattr:
I also use the append (chattr +a) attribute often. By setting the append attribute content can be added to the file but not altered. 

An example of using the append attribute is as follows:
#touch test.txt ; chattr +a ./test.txt; lsattr ./test.txt; 

 -----a-------e-- ./test.txt

We now can add to the file but can not replace the current file.
#echo test >> ./test.txt 

#sudo echo test > ./test.txt 
bash: ./test.txt: Operation not permitted

Thursday, November 28, 2013

Vim Windows and Tabs

 I truly love vim, a my first blog post I can not think of a better subject to talk about. A few was I use vim as a time saving tool are the below.

Vim Windows and Tabs

I administer several Nagios servers where I may need to open four or five host files and make a few quick changes. At times I use sed scripts but more often I open all the files with vim in vertical windows suing the following.

 vim -o webserver0{1..5}.cfg

-o opens each file in stacked  windows.
-O opens each file in side by side windows.
-p opens each file in its' own tab.

Then you can use regex replacments across all tabs or windows using windo or tabdo. A nice use of this is changing all http checks to https for webserver01-5. This change can be done suing the followind command.

:windo %s /check_http/check_https:g

To only make the change on your active window omit windo. In order to cycle through windows use ctfl+w w to move down a window or ctrl+w W to move up a window. All windows can be closed and saved using windo as well.

:windo x

If you are using tabs rather then windows tabdo can be used in place of windo. Using :tabn and :tabp to cycle the the next or prior tabs.