忍者ブログ

◆当blogは、Linuxサーバ構築する際の実際の設定手順を個人的メモとして記載しております。LinuC試験の役に立つ情報があるかも…?

LinuC(Linux技術者認定資格)&リナックスサーバ構築設定事例

   

【Linux】サーバーの状態確認(6)

疎通確認
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# ping 192.168.0.10
 Pinging 192.168.1.10 with 32 bytes of data:        

 Reply from 192.168.1.10: bytes=32 time<10ms TTL=128
 Reply from 192.168.1.10: bytes=32 time=20ms TTL=128
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

経路情報を表示する
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# traceroute 192.168.1.1
traceroute to itpro.nikkeibp.co.jp (202.214.174.88), 30 hops max, 38 byte packets
 1  192.168.1.1 (192.168.1.1)  0.386 ms  0.363 ms  0.322 ms
 2  218.xxx.xxx.xxx (218.xxx.xxx.xxx)  3.426 ms  4.137 ms  5.710 ms
 3  218.xxx.xxx.xxx (218.xxx.xxx.xxx)  7.711 ms  3.820 ms  3.123 ms
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

DNSサーバーへ問合せ(名前解決テスト)
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# nslookup 192.168.0.1
サーバー:  xxxxx.example.com
Address:  192.168.0.11

名前:    XXX.example.com
Address:  192.168.0.1

--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

PR

【Linux】サーバーの状態確認(1)

メモリやCPUの使用状況(5秒間隔で2回チェック)
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# vmstat 5 2
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0    300  51472 166104 116804    0    0     0     0    2    2  0  0 100  0  0
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---


現在動作中のプロセスを表示する
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.2  19360  1388 ?        Ss   Mar08   0:04 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Mar08   0:01 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Mar08   0:00 [migration/0]
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---


物理メモリ,仮想メモリの使用状況を表示する
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# free
             total       used       free     shared    buffers     cached
Mem:        502360     450904      51456          0     166104     116768
-/+ buffers/cache:     168032     334328
Swap:      1048568        300    1048268
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---


ハードディスクのパーテション情報などを表示する
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# df -h
Filesystem            Size  Used Avail Use% マウント位置
/dev/sda3             6.7G  3.4G  3.0G  54% /
tmpfs                 246M     0  246M   0% /dev/shm
/dev/sda1             248M   37M  199M  16% /boot
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

【Linux】サーバーの状態確認(5)

プロセスの状態表示
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.2  19360  1388 ?        Ss   Mar08   0:04 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Mar08   0:01 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Mar08   0:00 [migration/0]
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

パケットフィルタリングの状態表示
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# iptables -L
DROP       all  --  anywhere             255.255.255.255    
DROP       all  --  anywhere             224.0.0.1          
ACCEPT     all  --  192.168.0.0/24       anywhere           
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     tcp  --  172.20.0.0/24        anywhere            tcp dpt:ssh state NEW
ACCEPT     udp  --  172.20.0.0/24        anywhere            udp dpts:snmp:snmptrap
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

TCPラッパー (/etc/hosts.allow) によるアクセス制限①
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# cat /etc/hosts.allow
sshd: 192.168.0.16
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

TCPラッパー (/etc/hosts.allow) によるアクセス制限②
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# cat /etc/hosts.allowdeny
ALL: ALL
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

ホスト名とIPアドレスの対応付け
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

【Linux】サーバーの状態確認(4)

サービスの自動起動 on/off をリスト表示
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# chkconfig --list
NetworkManager  0:off 1:off 2:off 3:off 4:off 5:off 6:off
abrt-ccpp       0:off 1:off 2:off 3:off 4:off 5:off 6:off
abrtd           0:off 1:off 2:off 3:off 4:off 5:off 6:off
acpid           0:off 1:off 2:on 3:on 4:on 5:on 6:off
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

サービスの状態確認①
--- --- --- --- --- --- --- --- --- --- --- --- ---
# cat /etc/services
# service-name  port/protocol  [aliases ...]   [# comment]
tcpmux          1/tcp                           # TCP port service multiplexer
tcpmux          1/udp                           # TCP port service multiplexer
rje             5/tcp                           # Remote Job Entry
rje             5/udp                           # Remote Job Entry
echo            7/tcp
echo            7/udp
--- --- --- --- --- --- --- --- --- --- --- --- ---

サービスの状態確認②
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# service --status-all
NetworkManager は停止しています
abrt-ccpp hook is not installed
abrt-dump-oops は停止しています
abrtd は停止しています
acpid (pid  1909) を実行中...
atd (pid  2221) を実行中...
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

【Linux】サーバーの状態確認(3)

NICの設定
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0C:29:28:80:7C 
          inet addr:192.168.0.190  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9084557 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5672669 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1702563285 (1.5 GiB)  TX bytes:1512798167 (1.4 GiB)
eth1      Link encap:Ethernet  HWaddr 00:0C:29:28:80:86 
          inet addr:172.20.0.10  Bcast:172.20.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:294575 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:38004181 (36.2 MiB)
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

DNSの設定
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# cat /etc/resolv.conf
# Generated by NetworkManager
search cloud.local
nameserver 127.0.0.1
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

ネットワークの状態を表示する①
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
172.20.0.0      *               255.255.255.0   U         0 0          0 eth1
192.168.0.0     *               255.255.255.0   U         0 0          0 eth0
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

ネットワークの状態を表示する②
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.20.0.0      *               255.255.255.0   U     0      0        0 eth1
192.168.0.0     *               255.255.255.0   U     0      0        0 eth0
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

【Linux】サーバーの状態確認(2)

インストール済みパッケージを表示
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# rpm -qa
xorg-x11-drv-acecad-1.5.0-6.el6.x86_64
sg3_utils-1.28-4.el6.x86_64
net-snmp-utils-5.5-44.el6.x86_64
libXi-1.6.1-3.el6.x86_64
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

稼動状況をタイムリーに表示(「Shift+o」でソート)
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# top
top - 15:32:49 up 191 days,  6:47,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 102 total,   1 running, 101 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    502360k total,   452400k used,    49960k free,   166108k buffers
Swap:  1048568k total,      300k used,  1048268k free,   118104k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

11477 root      20   0 15028 1096  840 R  1.9  0.2   0:00.03 top
    1 root      20   0 19360 1388 1140 S  0.0  0.3   0:04.02 init
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

SELinuxが有効か無効かを調べる
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# getenforce
Enforcing
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

【Windows】インストールした更新プログラムを調べる方法 wmic qfe

例えば、2014/08/13に起こったWindowsアップデートでの不具合について
対処方法などは下記URLを参照して対応するとは思われますが、
まず自分のPCにある更新プログラムのバージョンを確認したい時などは
以下のコマンドの実行結果を調べておくのがお奨めです。
【不具合解消法】
   http://blogs.technet.com/b/jpsecurity/archive/2014/08/16/2982791-knownissue3.aspx
【更新プログラムのバージョン確認コマンド】

  wmic qfe > C:\HotFixID.txt

【PowerShell】コンソール出力をログに保存

PowerShellの実行結果(標準出力など) をログに保存する方法です。
(Linuxでいうところのscriptコマンド相当)
※このコマンドはISE環境では実行できません。


# ログ取得開始
Start-Transcript <ログファイル名>

# ログ取得終了
Stop-Transcript

【PowerShell】ローカルアカウント作成時に複数グループを設定する

ローカルアカウント作成時に複数グループを設定するサンプル作りました。

ファイル名:A2.ps1
# //変数格納//
  $computer = $Env:ComputerName
  $cdpath = (Get-Location).Path
# //text⇒CSV変換//
  $csv = import-csv -path $cdpath\A2.txt
# //テキスト情報の読込み//
  foreach($strUser in $csv)
  {
# //情報取得//
  $user = $struser.user
  $password = $struser.password
  $description =  $struser.description
  $group1 = $struser.group1
  $group2 = $struser.group2
# //初期化//
  Clear-Host
# //ユーザー作成//
  $ObjOU = [ADSI]"WinNT://$computer"
  $objUser = $objOU.Create("User", $user)
  $objUser.setpassword($password)
  $objUser.put("description",$description)
  $objUser.UserFlags = 0x10000 #パスワードを無期限に設定
  $objUser.SetInfo()
# //グループ設定 (1) //
  $objGroup = [ADSI]"WinNT://$computer/$group1"
  $objGroup.add("WinNT://$computer/$user")
  $objGroup.SetInfo()
# //グループ設定 (2) //
  $objGroup = [ADSI]"WinNT://$computer/$group2"
  $objGroup.add("WinNT://$computer/$user")
  $objGroup.SetInfo()
  }

##################################################
※読み込ませるデータに複数のグループを設定しておく
ファイル名:A2.txt
user,password,description,group1,group2
Test01,Password01,"説明文",administrators,users
Test02,Password01,"説明文",administrators,users
##################################################

【PowerShell】ローカルアカウントの設定変更スクリプト

既存しているローカルアカウントの設定を変更するサンプル作りました。

ファイル名:A1.ps1
# //変数格納//
  $computer = $Env:ComputerName
  $cdpath = (Get-Location).Path
# //text⇒CSV変換//
  $csv = import-csv -path $cdpath\A.txt

# //ファイル情報の読込み//

 foreach($strUser in $csv){
# //情報取得//
 $user = $struser.user
 $password = $struser.password
 $description =  $struser.description
# //初期化//
 Clear-Host
# //説明文とパスワードの設定変更//
 $objUser = [ADSI]"WinNT://$computer/$user"
 $objUser.setpassword($password)
 $objUser.description = $description
 $objUser.SetInfo()
}

更新日付

09 2026/10 11
S M T W T F S
1 2
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

RECOMMEND

プロフィール

HN:
Account
HP:
性別:
非公開
職業:
--- NODATA ---
趣味:
--- NODATA ---
自己紹介:
◆当blogは、Linuxサーバ構築する際の実際の設定手順を個人的メモとして記載しております。LinuC試験の役に立つ情報があるかも…?

リンク

<<前のページ  | HOME |  次のページ>>
Copyright ©  -- LinuC(Linux技術者認定資格)&リナックスサーバ構築設定事例 --  All Rights Reserved
Design by CriCri / Photo by Melonenmann / powered by NINJA TOOLS / 忍者ブログ / [PR]