2016年4月29日 星期五

Cisco 查看網路介面

R1#sh ip int brief
Interface IP-Address OK? Method Status Protocol
Ethernet0 unassigned YES unset administratively down down
Ethernet1 unassigned YES unset administratively down down
FastEthernet0 unassigned YES unset administratively down down
view raw 2016043004.sh hosted with ❤ by GitHub

Cisco 設定主機名稱

Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R1
R1(config)#exit
R1#wr
view raw 2016043003.sh hosted with ❤ by GitHub

Juniper 系統關機

root> request system halt
warning: The configuration has been changed but not committed
Halt the system ? [yes,no] (no) yes
*** FINAL System shutdown message from root@ ***
System going down IMMEDIATELY
Shutdown NOW!
[pid 1556]
view raw 2016043002 hosted with ❤ by GitHub

Juniper 回復原廠設定

root# load factory-default
warning: activating factory configuration
[edit]
root# commit
view raw 2016043001 hosted with ❤ by GitHub

2016年4月28日 星期四

Windows Power Shell 取得日期 Get-Date

Windows Power Shell 取得日期 Get-Date
PS C:\Users\Administrator> Get-Date -Format yyyMMdd
20160429
view raw 2016042901 hosted with ❤ by GitHub

Windows Power Shell 查看 Eventlog

取得所有 Eventlog
PS C:\> get-eventlog -list
Max(K) Retain OverflowAction Entries Log
------ ------ -------------- ------- ---
20,480 0 OverwriteAsNeeded 706 Application
20,480 0 OverwriteAsNeeded 0 HardwareEvents
512 7 OverwriteOlder 9 Hewlett-Packard
512 7 OverwriteOlder 0 Internet Explorer
20,480 0 OverwriteAsNeeded 0 Key Management Service
20,480 0 OverwriteAsNeeded 3,590 Security
20,480 0 OverwriteAsNeeded 3,658 System
15,360 0 OverwriteAsNeeded 91 Windows PowerShell
view raw 2016042808 hosted with ❤ by GitHub
查看前 50 筆 Log
PS C:\> get-eventlog -newest 50 Hewlett-Packard
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
9 三月 01 10:52 Error HPSF.exe 2000 HP Error ID: -2146233087 於 System.Windows.Ma...
8 三月 01 10:43 Error HPSF.exe 2000 HP Error ID: -2146233087 於 System.Windows.Ma...
7 三月 01 09:38 Error HPSF.exe 2000 HP Error ID: -2146233087 於 System.Windows.Ma...
6 二月 26 01:16 Error HPSF.exe 2000 HP Error ID: -2146233087 於 System.Windows.Ma...
5 二月 26 00:42 Error HPSF.exe 2000 HP Error ID: -2146233087 於 System.Windows.Ma...
4 二月 25 05:10 Error HPSF.exe 2000 HP Error ID: -2146233087 於 System.Windows.Ma...
3 二月 25 05:10 Error HPSF.exe 2000 HP Error ID: -2146233087 於 System.Windows.Ma...
2 二月 25 05:10 Error HPSF.exe 2000 HP Error ID: -2146233087 於 System.Windows.Ma...
1 二月 25 05:09 Error HPSF.exe 2000 HP Error ID: -2146233087 於 System.Windows.Ma...
view raw 2016042809 hosted with ❤ by GitHub

Linux 網路管理工具 ip

顯示 IP
[root@rhel7 ~]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:15:5d:22:b4:04 brd ff:ff:ff:ff:ff:ff
inet 192.168.100.100/24 brd 192.168.100.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::215:5dff:fe22:b404/64 scope link
valid_lft forever preferred_lft forever
view raw 2016042806.sh hosted with ❤ by GitHub
[root@rhel7 ~]# ip a s dev eth0 |grep inet |awk '{ print $2}'
192.168.100.100/24
fe80::215:5dff:fe22:b404/64
view raw 2016042805.sh hosted with ❤ by GitHub
顯示 Gateway
[root@rhel7 ~]# ip route
default via 192.168.100.254 dev eth0
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.100
169.254.0.0/16 dev eth0 scope link metric 1002
view raw 2016042807.sh hosted with ❤ by GitHub

Linux 防火牆管理工具 firewalld

列出目前狀態
[root@rhel7 ~]# firewall-cmd --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
view raw 2016042207.sh hosted with ❤ by GitHub
新增目標「暫時」
[root@rhel7 ~]# firewall-cmd --add-port=80/tcp
success
[root@rhel7 ~]# firewall-cmd --add-port=443/tcp
success
view raw 2016042208.sh hosted with ❤ by GitHub
[root@rhel7 ~]# firewall-cmd --list-all |grep ports
ports: 443/tcp 80/tcp
forward-ports:
view raw 2016042209.sh hosted with ❤ by GitHub
新增目標「永久」
[root@rhel7 ~]# firewall-cmd --permanent --add-port=80/tcp
success
[root@rhel7 ~]# firewall-cmd --permanent --add-port=443/tcp
success
view raw 2016042210.sh hosted with ❤ by GitHub
[root@rhel7 ~]# firewall-cmd --permanent --list-all
public (default)
interfaces:
sources:
services: dhcpv6-client ssh
ports: 443/tcp 80/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
view raw 2016042211.sh hosted with ❤ by GitHub

Linux 服務管理工具 systemctl

服務的停止與啟動
[root@rhel7 ~]# systemctl start httpd
[root@rhel7 ~]# systemctl stop httpd
[root@rhel7 ~]# systemctl restart httpd
view raw 2016042802.sh hosted with ❤ by GitHub
顯示所有服務
[root@rhel7 ~]# systemctl list-unit-files --type service
UNIT FILE STATE
auditd.service enabled
autovt@.service disabled
avahi-daemon.service enabled
brandbot.service static
console-getty.service disabled
console-shell.service disabled
cpupower.service disabled
crond.service enabled
dbus-org.fedoraproject.FirewallD1.service enabled
view raw 2016042803.sh hosted with ❤ by GitHub
啟動執行與停止服務
[root@rhel7 ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[root@rhel7 ~]# systemctl disable httpd
rm '/etc/systemd/system/multi-user.target.wants/httpd.service'
view raw 2016042804 hosted with ❤ by GitHub

Linux 縱向擷取工具 awk

[root@rhel7 ~]# tail /etc/passwd |awk -F: '{ print $1 }'
nobody
dbus
polkitd
avahi
avahi-autoipd
postfix
sshd
admin
apache
mysql
view raw 2016042801.sh hosted with ❤ by GitHub

2016年4月22日 星期五

Linux 橫向擷取工具 grep

[root@rhel7 ~]# cat [file] |grep 'option1\|option2\|option3'
view raw 20160422B01.sh hosted with ❤ by GitHub
[root@rhel7 ~]# systemctl list-unit-files --type service |grep 'firewall\|postfix\|httpd'
firewalld.service enabled
httpd.service disabled
postfix.service enabled
#查詢多筆資訊
view raw 20160422B02.sh hosted with ❤ by GitHub
[root@rhel7 ~]# egrep "postfix|mysql" /etc/passwd
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
mysql:x:998:997:MySQL server:/var/lib/mysql:/sbin/nologin
#使用[egrep]查詢多筆資訊
view raw 20160422B03.sh hosted with ❤ by GitHub

2016年4月21日 星期四

Linux 文字改寫的好幫手 sed

文字改寫的好幫手

文字替換

[root@rhel7 ~]# echo abcd |sed s/a/z/
zbcd
#文字替換
[root@rhel7 ~]# echo "abcd" |sed "s/a/z/"
zbcd
#引號
view raw 20160422A01.sh hosted with ❤ by GitHub
[root@rhel7 ~]# echo old old | sed s/old/new/g
new new
#文字替換
[root@rhel7 ~]# echo "abcd" |sed "s/a/z/"
zbcd
view raw 20160422A02.sh hosted with ❤ by GitHub
[root@rhel7 ~]# echo "this is bad" | sed 's/bad/good/w out.txt'
this is good
#替換文件內文字
[root@rhel7 ~]# cat out.txt
this is good
#查看結果
view raw 20160422A03.sh hosted with ❤ by GitHub
[root@rhel7 ~]# echo "今天心情很差" | sed s/差/好/g
今天心情很好
#中文範例
view raw 20160422A04.sh hosted with ❤ by GitHub

2016年4月19日 星期二

Linux RHEL7 網路連線查看工具 ss

簡介:自RHEL7發行開始,就已移除了舊有的「netstat」而使用「ss」來取代。

參數介紹

[root@rhel7 ~]# man ss
-a, --all
-l, --listening
-n, --numeric
ss -t -a
Display all TCP sockets.
Display all UDP sockets.
view raw 2016042202.sh hosted with ❤ by GitHub

基本服務查詢

[root@rhel7 ~]# ss -lt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:smtp *:*
LISTEN 0 50 *:mysql *:*
LISTEN 0 128 *:ndmp *:*
LISTEN 0 128 *:ssh *:*
LISTEN 0 100 ::1:smtp :::*
LISTEN 0 128 :::http :::*
LISTEN 0 128 :::ssh
view raw 2016042001.sh hosted with ❤ by GitHub
[root@rhel7 ~]# ss -ltn
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 50 *:3306 *:*
LISTEN 0 128 *:10000 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
view raw 2016042201.sh hosted with ❤ by GitHub