Mount -- Usage and examples

Mount a iso file

sudo mount -o loop -t iso9660 filename.iso /mountpoint
sudo umount iso/

[edit]A easy way

download two shell file, and add them to right click.

Using Nautilus Scripts
I am taking this tip from here first you need to download two scripts for mount iso images download from here for unmount iso images download from here
Once you have these two scripts you need to change the permissions using the following commands
sudo chmod +x /home/username/mount.sh

sudo chmod +x /home/username/unmount.sh

Now you need to copy them nautilus scripts

sudo mv /home/username/mount.sh ~/.gnome2/nautilus-scripts/

sudo mv /home/username/unmount.sh ~/.gnome2/nautilus-scripts/

[edit]Mount Partitions Automatically

Find usage and examples

'find' is a very important command in linux. The following are a few usage examples:

Find in the current directory

find . -maxdepth 1 -mindepth 1 -type f -name "*.java "


Find and out files with fullpath

find $PWD/dir -name "*.sh"
  • find /tmp -name core -type f -print | xargs /bin/rm -f
      Find files named core in or below the directory /tmp and delete them. 
 Note that this will work incorrectly if there
      are any filenames containing newlines or spaces.
  • find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
      Find files named core in or below the directory /tmp and delete them, 
processing filenames in such a way  that  file
      or directory names containing spaces or newlines are correctly handled.|


Tip: You just need to move .mp3 files and not directory, use:
# find / -iname "*.mp3" -type f -exec /bin/mv {} /mnt/mp3 \;
Find all directories having name mp3 and move:
# find / -iname "*.mp3" -type d -exec /bin/mv {} /mnt/mp3 \;
For performance you may need to consider using xargs command:
find / -iname "*.mp3" -type f | xargs -I '{}' mv {} /mnt/mp3

SSH

-->


Using SSH keys for Password-less Logins

ssh-keygen
ssh-copy-id user@hostname
note: remember to run command: ssh-add

[edit]How to prevent SSH terminal timeout

As root on your desktop (or client) machine, edit /etc/ssh/ssh_config and add the line:
ServerAliveInterval 60
That will send send a message to the server every 60 seconds, keeping the connection open. I prefer this way because I login to several machines every day, and I don’t have root access to all of them.

[edit]Transparent Multi-hop SSH

1. when want to connect to a server through multiple proxies, we can input the following code to ~/.ssh/config
#ControlMaster auto
#ControlPath   /home/zheng/.ssh/tmp/%h_%p_%r

Host irdut
  User yezheng
  HostName 202.118.75.106

#Host aoraki
#  ProxyCommand ssh -q ruapehu nc -q0 aoraki 22

Host 192.168.1.77
  User yezheng
  ProxyCommand ssh -q irdut nc -q0 %h 22

  • Host: Defines for which host or hosts the configuration section applies. The section ends with a new Host section or the end of the file.
  • User: Defines the username for the SSH connection. Useful if your username on the remote host is different from your local username.
  • HostName: Defines the literal hostname for the remote server. Useful if a nickname for the host is used in the Host line.
  • ProxyCommand: Specifies the proxy command for the connection. This command is launched prior to making the connection to Hostname. %h is replaced with the host defined in HostName and %p is replaced with 22 or is overridden by a Port directive. "2> /dev/null" prevents nc's "Killed by signal 1." message when it exits.

Bash

-->


This page mainly focuses on the syntax of bash.


use of array

#!/bin/bash

# We create an example array 'a' containing 16 values:
# array a = ( 0 1 2 3 4 ... 14 15 )
a=({0..15})

echo 'Linear array:'
echo ${a[*]}
echo "a specified dimension." 
echo ${a[5]}

# We now display this array 'a' in a 4x4 grid
echo 'Matrix array:'
for row in {1..4}; do
    for col in {1..4}; do
        echo -n ${a[((4*row+col-5))]}$'\t'
    done
    echo
done


VIM


how to copy using vim

  • press ESCAPE to change into command mode
  • put cursor on the beginning of textblock you want to copy
  • press v (vim will enter VISUAL mode)
  • move cursor to the end of textblock
  • press 'y' to copy (or 'x' for cut operation)
  • move cursor to the place you want to paste the text, then press 'p'

[edit]Color highlight in VIM

When in vim, try this:

Type : to get a command line,

Type 'runtime syntax/colortest.vim' to make sure you do in fact have the ability to display color from the server. (I know you said it did, but just to be sure! )

If the above worked, try editing the .vimrc file in your home directory to include the following lines: Code:
" Set syntax highlighting to always on
syntax enable

" Set the background to dark and the colorscheme to murphy
set background=dark
colorscheme murphy

" Set automatic filetype detection to on
filetype on
That should at least get you some color. You certainly don't have to keep the murphy colorscheme...I just included that bit so you'd have a color scheme to start with.

[edit]vim中文乱码的解决

  $vi ~/.vimrc
  let &termencoding=&encoding
  set fileencodings=utf-8,gbk
  $:wq

[edit]display special character

set list
set ff

linux运维常用命令

from http://deepin.iteye.com/blog/711813

1.删除0字节文件
find -type f -size 0 -exec rm -rf {} \;

2.
查看进程
按内存从大到小排列
ps -e   -o "%C   : %p : %z : %a"|sort -k5 -nr

3.
按cpu利用率从大到小排列
ps -e   -o "%C   : %p : %z : %a"|sort   -nr

4.
打印说cache里的URL
grep -r -a   jpg /data/cache/* | strings | grep "http:" | awk -F'http:' '{print "http:"$2;}'

5.查看http的并发请求数及其TCP连接状态:

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'


6. sed -i '/Root/s/no/yes/' /etc/ssh/sshd_config   sed
在这个文里Root的一行,匹配Root一行,将no替换成yes.

7.1.如何杀掉mysql进程:
ps aux |grep mysql |grep -v grep  |awk '{print $2}' |xargs kill -9 (从中了解到awk的用途)

killall -TERM mysqld

kill -9 `cat /usr/local/apache2/logs/httpd.pid`   试试查杀进程
PID

8.显示运行3级别开启的服务
:
ls /etc/rc3.d/S* |cut -c 15-   (从中了解到cut的用途,截取数据
)

9.如何在编写SHELL显示多个信息,用
EOF
cat << EOF
+--------------------------------------------------------------+
|       === Welcome to Tunoff services ===                |
+--------------------------------------------------------------+
EOF

10. for 的巧用(如给mysql建软链接
)
cd /usr/local/mysql/bin
for i in *
do ln /usr/local/mysql/bin/$i /usr/bin/$i
done

11. 取IP地址:

ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6-   或者

ifconfig   | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'

12.
内存的大小:
free -m |grep "Mem" | awk '{print $2}'

13.
netstat -an -t | grep ":80" | grep ESTABLISHED | awk '{printf "%s %s\n",$5,$6}' | sort

14.查看Apache的并发请求数及其TCP连接状态:

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

15.
因为同事要统计一下服务器下面所有的jpg的文件的大小,写了个shell给他来统计.原来用xargs实现,但他一次处理一部分,搞的有多个总和....,下面的命令就能解决啦.
find / -name *.jpg -exec wc -c {} \;|awk '{print $1}'|awk '{a+=$1}END{print a}'

CPU的数量(多核算多个CPU,cat /proc/cpuinfo |grep -c processor)越多,系统负载越低,每秒能处理的请求数也越多。


---------------------------------------------------------------------------------------
16   CPU
负载   # cat /proc/loadavg
检查前三个输出值是否超过了系统逻辑CPU的4倍。
 

18   CPU负载
   #mpstat 1 1
检查%idle是否过低(比如小于
5%)

19   内存空间
   # free
检查free值是否过低   也可以用
 # cat /proc/meminfo

20   swap空间
   # free
检查swap used值是否过高   如果swap used值过高,进一步检查swap动作是否频繁:

# vmstat 1 5观察si和so值是否较大

21   磁盘空间   # df -h
检查是否有分区使用率(Use%)过高(比如超过90%)   如发现某个分区空间接近用尽,可以进入该分区的挂载点,用以下命令找出占用空间最多的文件或目录:

# du -cks * | sort -rn | head -n 10

22   
磁盘I/O负载   # iostat -x 1 2
检查I/O使用率(%util)是否超过
100%

23   网络负载
   # sar -n DEV
检查网络流量(rxbyt/s, txbyt/s)是否过高


24   网络错误   # netstat -i
检查是否有网络错误(drop fifo colls carrier)   也可以用命令:
# cat /proc/net/dev

25 网络连接数目
   # netstat -an | grep -E “^(tcp)” | cut -c 68- | sort | uniq -c | sort -n

26   进程总数
   # ps aux | wc -l
检查进程个数是否正常 (比如超过
250)

27   可运行进程数目
   # vmwtat 1 5
列给出的是可运行进程的数目,检查其是否超过系统逻辑CPU的4倍


28   进程   # top -id 1
观察是否有异常进程出现


29   网络状态   检查DNS, 网关等是否可以正常连通

30   用户   # who | wc -l
检查登录用户是否过多 (比如超过50个)   也可以用命令:
# uptime

31   系统日志
   # cat /var/log/rflogview/*errors
检查是否有异常错误记录   也可以搜寻一些异常关键字,例如:

# grep -i error /var/log/messages
# grep -i fail /var/log/messages

32   
核心日志   # dmesg
检查是否有异常错误记录


33   系统时间   # date
检查系统时间是否正确


34   打开文件数目   # lsof | wc -l
检查打开文件总数是否过多


35   日志   # logwatch –print   配置/etc/log.d/logwatch.conf,将 Mailto 设置为自己的email 地址,启动mail服务 (sendmail或者postfix),这样就可以每天收到日志报告了。
缺省logwatch只报告昨天的日志,可以用# logwatch –print –range all 获得所有的日志分析结果。
可以用# logwatch –print –detail high 获得更具体的日志分析结果(而不仅仅是出错日志)。

36.杀掉80端口相关的进程
lsof -i :80|grep -v "PID"|awk '{print "kill -9",$2}'|sh

37.
清除僵死进程。
ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9

38.tcpdump 
抓包 ,用来防止80端口被人攻击时可以分析数据
# tcpdump -c 10000 -i eth0 -n dst port 80 > /root/pkts

39.
然后检查IP的重复数 并从小到大排序 注意 "-t\ +0"   中间是两个空格
# less pkts | awk {'printf $3"\n"'} | cut -d. -f 1-4 | sort | uniq -c | awk {'printf $1" "$2"\n"'} | sort -n -t\ +0

40.
查看有多少个活动的php-cgi进程
netstat -anp | grep php-cgi | grep ^tcp | wc -l

chkconfig --list | awk '{if ($5=="3:on") print $1}'
41.kudzu查看网卡型号
kudzu --probe --class=network
匹配中文字符的正则表达式: [\u4e00-\u9fa5]
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了
匹配双字节字符(包括汉字在内):[^\x00-\xff]
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)
匹配空白行的正则表达式:\n\s*\r
评注:可以用来删除空白行
匹配HTML标记的正则表达式:<(\S*?)[^>]*>.*?</\1>|<.*? />
评注:网上流传的版本太糟糕,上面这个也仅仅能匹配部分,对于复杂的嵌套标记依旧无能为力
匹配首尾空白字符的正则表达式:^\s*|\s*$
评注:可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式
匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
评注:表单验证时很实用
匹配网址URL的正则表达式:[a-zA-z]+://[^\s]*
评注:网上流传的版本功能很有限,上面这个基本可以满足需求
匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
评注:表单验证时很实用
匹配国内电话号码:\d{3}-\d{8}|\d{4}-\d{7}
评注:匹配形式如 0511-4405222 或 021-87888822
匹配腾讯QQ号:[1-9][0-9]{4,}
评注:腾讯QQ号从10000开始
匹配中国邮政编码:[1-9]\d{5}(?!\d)
评注:中国邮政编码为6位数字
匹配身份证:\d{15}|\d{18}
评注:中国的身份证为15位或18位
匹配ip地址:\d+\.\d+\.\d+\.\d+
评注:提取ip地址时有用
匹配特定数字:
^[1-9]\d*$    //匹配正整数
^-[1-9]\d*$   //匹配负整数
^-?[1-9]\d*$   //匹配整数
^[1-9]\d*|0$  //匹配非负整数(正整数 + 0)
^-[1-9]\d*|0$   //匹配非正整数(负整数 + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$   //匹配正浮点数
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$  //匹配负浮点数
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$  //匹配浮点数
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$   //匹配非负浮点数(正浮点数 + 0)
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$  //匹配非正浮点数(负浮点数 + 0)
评注:处理大量数据时有用,具体应用时注意修正
匹配特定字符串:
^[A-Za-z]+$  //匹配由26个英文字母组成的字符串
^[A-Z]+$  //匹配由26个英文字母的大写组成的字符串
^[a-z]+$  //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$  //匹配由数字和26个英文字母组成的字符串
^\w+$  //匹配由数字、26个英文字母或者下划线组成的字符串
评注:最基本也是最常用的一些表达式

Sed

--&gt;


What is it

sed (stream editor) is a Unix utility that parses text files and implements a programming language which can apply textual transformations to such files. It reads input files line by line (sequentially), applying the operation which has been specified via the command line (or a sed script), and then outputs the line. It was developed from 1973 to 1974 as a Unix utility by Lee E. McMahon of Bell Labs,[1] and is available today for most operating systems.[2]



Usag

The following example shows a typical use of sed, where the -e option indicates that the sed expression follows:
sed -e 's/oldstuff/newstuff/g' inputFileName &gt; outputFileName
In many versions, the -e is not required to precede the expression. The s stands for substitute. The g stands for global, which means that all matching occurrences in the line would be replaced. The regular expression (i.e. pattern) to be searched is placed after the first delimiting symbol (slash here) and the replacement follows the second symbol. Slash is the conventional symbol. Any other could be used to make syntax more readable if it does not occur in the pattern or replacement (see below).
Under Unix, sed is often used as a filter in a pipeline:
generate_data | sed -e 's/x/y/g'
That is, generate the data, and then make the small change of replacing x with y.
Several substitutions or other commands can be put together in a file called, for example, subst.sed and then be applied using the -f option to read the commands from the file:
sed -f subst.sed inputFileName &gt; outputFileName
Besides substitution, other forms of simple processing are possible. For example, the following uses the d command to delete lines that are either blank or only contain spaces:
sed -e '/^ *$/d' inputFileName 
This example used some of the following regular expression metacharacters:
  • The caret (^) matches the beginning of the line.
  • The dollar sign ($) matches the end of the line.
  • The asterisk (*) matches zero or more occurrences of the previous character.
Complex sed constructs are possible, allowing it to serve as a simple, but highly specialised, programming language. Flow of control, for example, can be managed by the use of a label (a colon followed by a string) and the branch instruction b. An instruction b followed by a valid label name will move processing to the block following that label. If the label does not exist then the branch will end the script.

[edit]Samples

[edit]Regex print

sed -rn '\|euro| s|.*&gt;([0-9.]+) &amp;euro.*|\1|p' 

sed -rn '\|KLb| s|.*BM25b=([0-9.]+)_QEAdap_RocProx4w=([0-9.]+)F=0.6_([0-9.]+)_([0-9]+)_KLb([0-9.]+)_([0-9.]+).gz.eval:Average Precision: ([0-9.]+)|\4\t\3\t\2|p'`


-r  :turn on extended regex.
-n  :don't print every line.

\|euro|  :match only lines containing "euro".  The address
  :pattern traditionally uses /string/, but you can
  :change it to a different character by preceding
  :it with a backslash.

s|x|y|  :the standard sed substitution pattern.  Again, it's 
  :traditionally s/x/y/, but any basic ascii character
  :can be used.

.*&gt;  :a string of any kind of character, ending with "&gt;".

(..)  :designates the part of the match to be captured.

[0-9.]+  :a string of digits and/or periods of any length
  :(but at least one).

 &amp;euro.* :followed by [space]&amp;euro, and the rest of the line.

\1  :insert the captured part into the output string.

p  :print the results.

  • a running example
out="QEvenBM25b=0.3_QEAdap_RocProx4w=20F=0.6_20_5_KLb0.3_117.gz.eval:Average Precision: 0.3281"
map=`echo $out| cut -d : -f 3`;
echo $out |sed -rn '\|KLb| s|.*BM25b=([0-9.]+)_QEAdap_RocProx4w=([0-9]+)F=0.6_20_5_KLb([0-9.]+)_117.gz.eval:Average Precision: ([0-9.]+)|\4\t\3\t\2|p'

[edit]print specified lines

sed -n '1,50p' topics.RF08

[edit]Replace word / string syntax

1. sed -i 's/old-word/new-word/g' *.txt
2. find . -type f | xargs sed -i 's/zheng/ben/g'

3. find . -type f | while read f;do sed -i 's/home\/ben\/tr.ben/media\/disk\/ben/g' $f; done
GNU sed command can edit files in place (makes backup if extension supplied) using -i option. == Append a line after a specified line ==
sed -i '/TERRIER_HOME/a\whatever' optimiseDFR-cpost-adv-cent.sh
GNU sed command can edit files in place (makes backup if extension supplied) using -i option.

[edit]To delete a line

sed '/yourword/d' yourfile

[edit]To delete a word

sed 's/yourword//g' yourfile

[edit]To delete two words for a file simultaneously

sed -e 's/firstword//g' -e 's/secondword//g' yourfile
or
sed  's/firstword//g;s/secondword//g' yourfile

[edit]delete a line containing a specific word

sed '/yourword/d' yourfile

[edit]delete only the word use

sed 's/yourword//g' yourfile

[edit]delete two words for a file simultaneously use

 sed -e 's/firstword//g' -e 's/secondword//g' yourfile
or
 sed  's/firstword//g;s/secondword//g' yourfile
In the next example, sed, which usually only works on one line, removes newlines from sentences where the second sentence starts with one space. Consider the following text:
This is my cat
 my cat's name is betty
This is my dog
 my dog's name is frank
The sed script below will turn it into:
This is my cat my cat's name is betty
This is my dog my dog's name is frank
Here's the script:
sed 'N;s/\n / /;P;D;'
  • (N) add the next line to the work buffer
  • (s) substitute
  • (/\n /) match: \n (newline character in Unix) and one space
  • (/ /) replace with: one space
  • (P) print the top line of the work buffer
  • (D) delete the top line from the work buffer and run the script again

More useful and complex is transposing an XML table into a CSV:
sed -rn '{s/  *//g;//{s/.*//g;H};///g;H};/&lt;\/row&gt;/{x;s/^\r*\n//;s/\r*\n\r*/","/g;s/^([^\r\n]*)/"\1"/;p};/
First clear out all the extraneous whitespace:
s/  *//g
If the current line is a blank line, add a blank line to the hold space:
//{s/.*//g;H}
If there is an actual value in the field, strip the xml and add the value to the hold space:
//{s/&lt;\/*field&gt;//g;H}
If it is the end of a row (
), then get the hold space, replace the newlines with '","', add quotes to the beginning and end and then print the line:
/&lt;\/row&gt;/{x;s/^\r*\n//;s/\r*\n\r*/","/g;s/^([^\r\n]*)/"\1"/;p}
If it is the beginning of a row, clear the hold space by adding a blank line:
/

[edit]Exotic examples

Despite the inherent limitations, sed scripts exist for games such as sokoban, arkanoid,[5] and an implementation of tetris.[6]

Dnsmasq Usage and Examples


Dnsmasq


Contents

 [hide]

[edit]1. Introduction

This first paragraph is taken from the dnsmasq home page.
Dnsmasq is a lightweight, easy to configure DNS forwarder and DHCP server. It is designed to provide DNS and, optionally, DHCP, to a small network. It can serve the names of local machines which are not in the global DNS. The DHCP server integrates with the DNS server and allows machines with DHCP-allocated addresses to appear in the DNS with names configured either in each host or in a central configuration file. Dnsmasq supports static and dynamic DHCP leases and BOOTP/TFTP for network booting of diskless machines.

[edit]2. Installation.

[edit]2.1. Install Using The 'apt-get' Software

Use the command line below . You will need the universe repository in your software sources list.
Install command 
sudo apt-get install dnsmasq dnsmasq-base 

[edit]3. Initialization and Configuration.

[edit]3.1. The example system used in this HOWTO

The server where dnsmasq is running its DNS and DHCP services is called linux60 (192.168.0.7), The Router is IP 192.168.0.1. There are a mixture of real and virtual machines all using these services. All machines are in the local domain example.com. The client machines will have names like linux12 or kvmubuntu.

[edit]3.2. Setting up the server

[edit]3.2.1. Make backup copies of 'conf' files.

Start by making a copy of the files we will be changing so you can always go back to a know starting point.
Copy original configuration files: cd /etc cp dnsmasq.conf hosts resolve.conf ~/mybackups

[edit]3.2.2. Setting up /etc/dnsmasq.conf

Looking at the file /etc/dnsmasq.conf first. Below is a good starting point to get things up and running. The lines are listed in the same order as they appear in the default file. Just uncomment and amend them as necessary. (Remove the '#' from the beginning of the line)
Example /etc/dnsmasq.conf: 
domain-needed 
bogus-priv 
expand-hosts 
domain=example.com 
dhcp-range=192.168.0.20,192.168.0.50,24h 
What these lines will do for you.
domain-needed This tells dnsmasq to never pass short names to the upstream DNS servers. If the name is not in the local /etc/hosts file then "not found" will be returned. bogus-priv All reverse IP (192.168.x.x) lookups that are not found in /etc/hosts will be returned as "no such domain" and not forwarded to the upstream servers. expand_hostsSo we can see our local hosts via our home domain without having to repeatedly specify the domain in our /etc/hosts file. domain This is your local domain name. It will tell the DHCP server which host to give out IP addresses for. dhcp-range This is the range of IPs that DHCP will serve: 192.168.0.20 to 192.168.0.50, with a lease time of 24 hours. The lease time is how long that IP will be linked to a host. Dnsmasq will, set or find out automatically, lots of common networking and connection values. These do not need to be set unless you are paranoid or like to specifically set these things. Which is rather nice of dnsmasq, don't you agree?
broadcast address network mask router parameters interface (eth0) and IP address to listen on

[edit]3.2.3. Setting the server /etc/hosts file

The /etc/hosts file on the example server will look like this. Leave the IPv6 stuff as it was.
Example /etc/hosts: 
127.0.0.1 localhost 
192.168.0.7 linux60 
3.2.4. Setting the server /etc/resolve.conf file
One last thing to do it set the localhost or loop device on the server as a nameserver so it can use the DNS service that it is running. Add the nameserver line below to the top of the list in /etc/resolv.conf.
Example /etc/resolve.conf:
nameserver 127.0.0.1

[edit]3.3. Setting up the clients

[edit]3.3.1. Make backup copies of 'conf' files.

Start by making a copy of the files we will be changing so you can always go back to a know starting point.
Copy original configuration files: 
cd /etc 
cp dhcp3/dhclient.conf hosts resolve.conf  ~/mybackups 
The /etc/hosts file on the client machines should look similar to this. Leave the IPv6 stuff alone.

Example /etc/hosts: 
127.0.0.1 localhost 
127.0.1.1 linux12 
Note: There should be no need to change the hosts file from the default one created by Ubuntu.
3.3.2. Clients for DNS.
In the example setup our server is linux60 or 192.168.0.7 it is the only machine with a static IP address. This is necessary as we need to tell the other machine were to look for the DNS service. So we need to tell the other machines were to get their DNS service from to take advantage of our shiny new server. We do this by adding a line to /etc/resolv.conf. I put it as the first nameserver in the file.
Example /etc/resolve.conf: nameserver 192.168.0.7

[edit]3.3.3. Clients for DHCP.

The only change here that we need to do is to make sure that when the host requests an IP address it passes its own hostname to the DHCP server. So the other machines can use its name to look up the IP address it was just given. So for example if we are setting up our workstation called linux12 that is in our fictitious domain example.com we would add the following line to /etc/dhcp3/dhclient.conf
Example /etc/dhcp3/dhclient.conf: send host-name "linux12.example.com"; You can now reboot linux12. During which time it will talk to our new DHCP server request a new IP address. The server will remember which IP address it gave out to linux12 and it and other machines on the network will be able to ping linux12. No more needing to know which machine has which IP address.

[edit]4. Testing & Troubleshooting

[edit]4.1. Testing the DNS server

[edit]4.1.1. Locally on the server and on remote hosts

The simplest way to test that your DNS is up and running it to use the dig utility. When you look at the output from dig the part we are interested in is the third and forth line from the end. Just use dig to see the output.

[edit]4.2. Testing DHCP.

Assuming your dnsmasq server is already setup and working. Start up one of the other hosts. After it has booted look at the output from ifconfig looking at the second line for the network interface and the inet addr should be within the DHCP range you set on the server.
Code: inet addr:192.168.0.7 Bcast:192.168.0.255 Mask:255.255.255.0 From the dnsmasq server you should be able to ping the machine you just booted by name and vice-versa.
Make sure you have turned off all other DHCP servers on your system.
You can test that you are using the dnsmasq DHCP server by making a range one just one IP address in /etc/dnsmasq.conf, restarting the dnsmasq server and rebooting the client machine. It should now be using that one IP address.

[edit]5. Stopping And Starting The dnsmasq Daemon.

This is really simple just run the dnsmasq startup script in /etc/init.d with stop, start or restart. That was simple
Code: 
sudo /etc/init.d/dnsmasq stop 
sudo /etc/init.d/dnsmasq start 
sudo /etc/init.d/dnsmasq restart 

  • note:if this service does not start automatically, we can use "bum" to do this.

[edit]6. reverse DNS resolution

配置反向dns解析 (reverse DNS)
执行vim /etc/dnsmasq.conf,打开dnsmasq的配置文件,找到addn_hosts这一行,去掉前面的#
修改此行 为 :
addn-hosts=/etc/dns_add_hosts
然后我们 建立 /etc/dns_add_hosts文件, vim /etc/dns_add_hosts
加入下面内容
10.8.0.1 dns.netroby.com
每一行对应着 IP 域名
保存后重启dnsmasq服务 /etc/init.d/dnsmasq restart 反向解析就已经生效了。

[edit]6. Further Information. Advanced stuff.

I would strongly suggest that you get the basic stuff working and sorted out before doing anything in this section. .
Verisign, back in September 2003, decided to push unwanted advertising your way when there was no domain registered rather than returning the "no such domain" message. To stop this type of unnecessary annoyance you can use the following option in /etc/dnsmasq. If you find more IPs then you simply add one more line.
Code: bogus-nxdomain=64.94.110.11 To find out if your ISP or the whoever it providing your upstream DNS is doing this to you , just try looking up, with dig totally, random domain names if they return a valid IP address and the SAME IP address. Add it to the list of bogus-nxdomain IP addresses. Then restart the dnsmasq service.
You can even stop some of those pesky advertisements getting to your browsers by redirecting domains to a local IP address, localhost is good.
Code: 
address=/doubleclick.net/127.0.0.1 

[edit]6.1. Links I Found Useful

dnsmasq Home page


-->

Popular Posts