Wednesday, February 25, 2015
linux command (network)
Add Network (network command)
(1)add interface
[root@server ~]#cd /etc/sysconfig/network-scripts
[root@server ~]#vi ifcfg-eth0
DEVICE="eth2"
BOOTPROTO="dhcp"
HWADDR="00:02:C9:27:59:FE"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
IPV6INIT="no"
(2)If set ip, will not active after reboot.
When we set some ip address, after reboot or services restart will not active. This means that we have to kill the temporary store ip address. This often occur when we had a dhcp Ip address, then we wants to change to a static. But i also found out that if i wants to change a new network card, will also happen, the ip will not change.
Please set ip address first, then clear this.
[root@server ~]#cd /etc/udev/rules.d
[root@server ~]#rm 70-persistent-net.rules
(3) show ip address
[root@server ~]#ifconfig
(4) show ip interface
[root@server ~]#ip a
(5) ethtool - query or control network driver and hardware settings
ethtool ethernet interface
#ethtool eth0
This will let you see your link rate, support wake on lan, lan detect or not, and so on.
(6) enable your interface
#ifdown eth0
#ifup eth0
(7) ping
ping ip address
ping -c 1 ipaddress ==>ping one second
(8) Search dhcp client ip address, or bmc ip address
cat /var/log/messages | grep BMC MAC address
example: cat /var/log/messages | grep xx:xx:xx:xx:xx:xx
(9) changed Server name
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=putXX
(1)add interface
[root@server ~]#cd /etc/sysconfig/network-scripts
[root@server ~]#vi ifcfg-eth0
DEVICE="eth2"
BOOTPROTO="dhcp"
HWADDR="00:02:C9:27:59:FE"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
IPV6INIT="no"
(2)If set ip, will not active after reboot.
When we set some ip address, after reboot or services restart will not active. This means that we have to kill the temporary store ip address. This often occur when we had a dhcp Ip address, then we wants to change to a static. But i also found out that if i wants to change a new network card, will also happen, the ip will not change.
Please set ip address first, then clear this.
[root@server ~]#cd /etc/udev/rules.d
[root@server ~]#rm 70-persistent-net.rules
(3) show ip address
[root@server ~]#ifconfig
(4) show ip interface
[root@server ~]#ip a
(5) ethtool - query or control network driver and hardware settings
ethtool ethernet interface
#ethtool eth0
(6) enable your interface
#ifdown eth0
#ifup eth0
(7) ping
ping ip address
ping -c 1 ipaddress ==>ping one second
(8) Search dhcp client ip address, or bmc ip address
cat /var/log/messages | grep BMC MAC address
example: cat /var/log/messages | grep xx:xx:xx:xx:xx:xx
(9) changed Server name
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=putXX
Linux command
PART 1 SIMPLE COMMAND
(1) list directory contents (refer to window dir)
command: ls
Description /purpose: Print or list the file or folder in this directory
[root@server ~]# ls
command: ll
Description /purpose: Print or list the file or folder in this directory, but this will show information.
[root@server ~]# ll
(2) print name of current/working directory (pwd)
Description /purpose: show which directory or path you are in right now.
[root@server ~]# pwd
/root
(3) copy (cp)
Description /purpose: copy file or create backup
#cp dhcp.conf dhcp.conf.bk
(4)move or rename file ( mv)
Description /purpose: rename a file name, or generate a file
#mv old.txt new.txt
(5) cat
Description /purpose: read a file name
cat 123.txt
(6)modify text (vi or vim)
Description /purpose: to modify some file
vi is modify, and vim is improve, which will have show in different color.
Some variable need to used
vi
vim
:q! ==>exit without saving
:w! ==>save
:wq!==>save and quit
:x!==>save and exit
? or / ==>search
Note: For more information, please refer shell script
(7) touch
Description /purpose:to generate a file. Different between vi is it don't have to save to generate a file. It will generate a file if input touch command.
touch aaa.txt
(8)tail
Description /purpose: output the last part of files
will print last 10 line
#tail /var/log/message
output appended data as the file grows.
#tail -f
difference from cat versus tail
tail is different from cat, is cat will read all the file once, but tail will not. For example if you have a log file, you cat log file, it will read all the line from first line to last line. But tail will read last line, and if the file still have message, it will also show.
(9) clear
Description /purpose:clear the terminal screen
#clear
PART 2 Intermediate (common used and file related)
1. extract file
2. compress file
3. mount
what is mount?
A mount is where I wants to mount a directory into one folder. Mount this command can used for many ways.
Basely mount this command is like if i have a directory names test, if i wants to mount a directory "dhcp" into test this directory. Directory test all the data will be used by dhcp this directory. In other word mean all test directory will be gone, will only appear dhcp data. If you umount it, it will be appear.
Mount this command can be used for:
Mount for folder to folder which is like shortcut
# mount --bind /etc/dhcp /dhcpfile_test
Mount for usb drive to /mnt directory
Mount for network
4 link or shortcut
command "ln -s"
ln -s orginally folder or file shortcut
# ln -s /etc/dhcp/ /dhcpfile
5 set date
date MMddhhmmyyyy
(1) list directory contents (refer to window dir)
command: ls
Description /purpose: Print or list the file or folder in this directory
[root@server ~]# ls
command: ll
Description /purpose: Print or list the file or folder in this directory, but this will show information.
[root@server ~]# ll
(2) print name of current/working directory (pwd)
Description /purpose: show which directory or path you are in right now.
[root@server ~]# pwd
/root
(3) copy (cp)
Description /purpose: copy file or create backup
#cp dhcp.conf dhcp.conf.bk
(4)move or rename file ( mv)
Description /purpose: rename a file name, or generate a file
#mv old.txt new.txt
(5) cat
Description /purpose: read a file name
cat 123.txt
(6)modify text (vi or vim)
Description /purpose: to modify some file
vi is modify, and vim is improve, which will have show in different color.
Some variable need to used
vi
vim
:q! ==>exit without saving
:w! ==>save
:wq!==>save and quit
:x!==>save and exit
? or / ==>search
Note: For more information, please refer shell script
(7) touch
Description /purpose:to generate a file. Different between vi is it don't have to save to generate a file. It will generate a file if input touch command.
touch aaa.txt
(8)tail
Description /purpose: output the last part of files
will print last 10 line
#tail /var/log/message
output appended data as the file grows.
#tail -f
difference from cat versus tail
tail is different from cat, is cat will read all the file once, but tail will not. For example if you have a log file, you cat log file, it will read all the line from first line to last line. But tail will read last line, and if the file still have message, it will also show.
(9) clear
Description /purpose:clear the terminal screen
#clear
PART 2 Intermediate (common used and file related)
1. extract file
tar -zxvf extract.tar.gz
#tar -zxvf filename.tar.gz
tar -tzvf compressed.tar.gz
tar -zcvf filnename.tar.gz 'folder destination/'
#tar -zcvf filnename.tar.gz folder /test
what is mount?
A mount is where I wants to mount a directory into one folder. Mount this command can used for many ways.
Basely mount this command is like if i have a directory names test, if i wants to mount a directory "dhcp" into test this directory. Directory test all the data will be used by dhcp this directory. In other word mean all test directory will be gone, will only appear dhcp data. If you umount it, it will be appear.
Mount this command can be used for:
Mount for folder to folder which is like shortcut
# mount --bind /etc/dhcp /dhcpfile_test
Mount for usb drive to /mnt directory
Mount for network
4 link or shortcut
command "ln -s"
ln -s orginally folder or file shortcut
# ln -s /etc/dhcp/ /dhcpfile
5 set date
date MMddhhmmyyyy
BATCH(.bat) SCRIPT(window)
PART1 SIMPLE
(1)CREATE FOLDER
set /P id=Enter id:
mkdir %id%
(2) FOLDER NAME WITH DATE
PART2 Mixed function script
(1) user enter Devices name and IP address
@echo off
for /F "tokens=1-4 delims=/ " %%A in ('date/t') do (
set DateDay=%%A
set DateMonth=%%B
set DateYear=%%C
)
set CurrentDate=%DateDay%-%DateMonth%-%DateYear%
set /P name=Enter name of folder:
set /p bmc_ip="Enter BMC IP Address: "
mkdir %CurrentDate%_%name%
@echo on
ipmitool -I lan -H %bmc_ip% -U USERID -P PASSW0RD sensor > %CurrentDate%_%name%/SENSOR.TXT
ipmitool -I lan -H %bmc_ip% -U USERID -P PASSW0RD sel list > %CurrentDate%_%name%/list.TXT
ipmitool -I lan -H %bmc_ip% -U USERID -P PASSW0RD sel elist > %CurrentDate%_%name%/elist.TXT
output:
Enter name of folder: DUT1-1
Enter BMC IP Address: 192.168.1.2
(1)CREATE FOLDER
set /P id=Enter id:
mkdir %id%
(2) FOLDER NAME WITH DATE
for /F "tokens=1-4 delims=/ " %%A in ('date/t') do (
set DateDay=%%A
set DateMonth=%%B
set DateYear=%%C
)
set CurrentDate=%DateMonth%-%DateDay%-%DateYear%
mkdir %CurrentDate%
(3) PING
@echo off
set /p a="Enter IP Address or Name: "
ping %a%
pause
(4)
PART2 Mixed function script
(1) user enter Devices name and IP address
@echo off
for /F "tokens=1-4 delims=/ " %%A in ('date/t') do (
set DateDay=%%A
set DateMonth=%%B
set DateYear=%%C
)
set CurrentDate=%DateDay%-%DateMonth%-%DateYear%
set /P name=Enter name of folder:
set /p bmc_ip="Enter BMC IP Address: "
mkdir %CurrentDate%_%name%
@echo on
ipmitool -I lan -H %bmc_ip% -U USERID -P PASSW0RD sensor > %CurrentDate%_%name%/SENSOR.TXT
ipmitool -I lan -H %bmc_ip% -U USERID -P PASSW0RD sel list > %CurrentDate%_%name%/list.TXT
ipmitool -I lan -H %bmc_ip% -U USERID -P PASSW0RD sel elist > %CurrentDate%_%name%/elist.TXT
output:
Enter name of folder: DUT1-1
Enter BMC IP Address: 192.168.1.2
Subscribe to:
Posts (Atom)