CentOS7 chrony 時刻が同期できない

ntpd とchroyd が両方動いていたので、ntpdを停止。

チェックすると、同期できない。

ntpdを動かしても同期できない。

設定は変更していない。

 

ntpdate ntp.nict.jp

で時刻を合わせようとすると、名前解決ができない。

DNSが動いていませんでした。

systemctl restart named-chroot

CentOS7 freeradius 再起動起動しない

先日カーネルのアップデートを行いました。

が、起動しなくなるので、以前のカーネルで動かしています。

yum update でエラーが出ているのを解消したかったのです。

 

そして、再起動して無事起動するか確認。

Raidドライバの都合で、起動しなくなることがあるのです。

 

もちろん、前のバージョンで起動するように設定してあるので、

そのまま起動するはずですが。

 

無事起動。

? httpd自動起動していない。自動起動設定がされていなかったか?

!?   radiusd が起動できずに失敗する。

 

? mariadb自動起動していない。・・・・

 

時間が遅かったのであとは翌日です。

 

翌朝、systemctl start radiusd あっさりきどうしました。?????

 

あああ、radiusdを起動しようとしたときに、mariadbが起動していなかったから起動できなかったのですね。ログを見ればわかったのかな。

Cisco Startシリーズ C841M-4X-JSEC/K9/START でPAT(IPマスカレード)が変換されない。

内部のIPを外部のIPに変換するPATですが、
今回は内部ネットワークの別セグメントへの接続にPATを使用します。

192.168.0.0/24 と 192.168.40.0/24 の間にC841Mを設置し、

PATで192.168.2.※→ 192.168.40.1 に変換。
というのが当初の目論見でした。
□interface GigabitEther0/5 を 192.168.0.252 255.255.255.0 に設定。
configure terminal
interface Gi0/5
ip address 192.168.0.252 255.255.255.0
ip nat inside
no shutdwon

□ interface GigabitEther0/4 を 192.168.40.1 255.255.255.0に設定。
interface Gi0/4
ip address 192.168.40.1 255.255.255.0
ip nat outside
no shutdown

access-list 1 に 192.168.0.0 のアクセス許可を設定
access-list 1 permit 192.168.0.0 0.0.0.255

ip nat inside source list 1 interface GigabitEther0/5 overload

以上の設定でOKなはずです。192.168.40.11 にホスト(Windows10)を設置して
ping を送信すると・・・返ってきました!
次にパケットの送信IPを確認するために、

ホストでWireShark を起動して、もう一度pingします。
すると、送信元のIPは、なんと192.168.0.252で変換されていない??のでした。
しかし、設定前はping が通らなかったので、

全てが間違っているわけでもなさそうです。
show ip nat translationsで変換テーブルを表示しても表示されないので、

やはり変換されていないようです。
PATの設定を削除しても、なぜかpingは通り続け、まったく意味が分かりません。

-------------------------------------------------------------------------------------------------
意味が分からないので、基本から、ということで静的NATから試していくことにしました。
静的NAT → 動的NAT と試していきましたが、NATでは全く問題がありませんでした。

show ip nat translations すると
Inside globalは変換されたアドレス 192.168.40.※
Inside localはpingを送信したPCのIP 192.168.0.2

と表示されて変換されている様子がわかります。
さて、PATに戻ります。
--------------------------------------------------------------------------------------------------

PATをインターフェースに直接割り当てるのではなく、poolを作成し、そのアドレスに割り当てるように変更してみました。
① PAT変換後となる内部グローバルアドレスのプールを定義
ip nat pool TEST 192.168.40.7 192.168.40.7 netmask 255.255.255.0

② PAT変換対象となる送信元IPアドレスACLで定義
no access-list 3 permit 192.168.0.0 0.0.0.255

③ 内部ローカルアドレスを定義する「ACL」と、外部グローバルアドレスとする「プール」を関連づけ
ip nat inside source list 3 pool TEST overload

④ どのインターフェースを「内部ネットワーク」または「外部ネットワーク」に指定するのかを定義

interface GigabitEther0/5
ip nat inside

interface GigabitEther0/4
ip nat outside

とこれでホスト側でWireSharkを起動したところ、見事に192.168.40.7 に送信元IPが変換されました。
show ip nat translations も予想道理になり、思った通りに動作させることができました。

なぜ、Interface GigabitEther0/5を直接に割り当てたときに、IPが変換されないのかは・・・謎です。

※ちなみにvlan10 を作成してそれのip nat inside にして、
interface GigabitEhter0/1 のswitchport access vlan 10
でGigabitEther0/1をvlan10に割り当ててみましたが、
Natテーブルを確認すると、192.168.0.2 → 192.168.2.252 という変換が行われて通信していました。???

Windows 10 Out Of Range  範囲外 で 画面が映らない

ディスプレイを変えてみると映ることもあります。

 

ダメならば、ウィンドウズのタイトル画面が表示されたときに、電源長押しで電源を切ります。3回目の起動で自動修復モードに入ります。

詳細オプションのスタートアップ設定で再起動します。

 

低解像ビデオモードを選択すれば無事にディスプレイが表示されます。

VB.NET WindowsService から画面をロックする 2 リモートアクセスでもロックする

 さて、画面ロックのやり方がわかって喜んでいたのだが、

 

WindowsServer2016でテストしたところ、画面ロックが動作しない。

・・・しばらく試した末に、あきらめかけましたが、

頑張って調べました。

 

アクティブなユーザートークンを取得して、そのユーザーとして、LockWorkStationしているので、リモートデスクトップでユーザートークンが取得できずに、ロックできないという現象のようです。

 

1「WTSGetActiveConsoleSessionId」関数で物理コンソールのセッションIDを取得する。

2 「WTSQueryUserToken」関数で取得したセッションIDのユーザートークンを主とする。

 

とやっているのですが、つまり物理コンソールでないとだめだということです。

リモートデスクトップではセッションIDを取得することができません。

 

代わりに、「WTSEnumerateSessions」

を使用してアクティブなリモートデスクトップのセッションIDを取得し、

そのセッションIDでWTSQueryUserToken 関数を使用して、ユーザートークンを取得するということをやります。

 

それでは、まず、WTSEnumerateSession を使えるように、クラスを作ります。

ここを参照しました。

http://hongliang.seesaa.net/article/7243455.html

Imports System
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports System.Text
 
Public Class TerminalService
    Public Shared ReadOnly CurrentServerHandle As IntPtr = IntPtr.Zero
    Public Shared Function GetSessionInfos(ByVal server As IntPtrAs WTSSessionInfo()
        Dim buffer As IntPtr  '返ってくる配列を受け取るポインタ。
        Dim count As Integer  '数。どちらも初期化不要。
        '早速実行。失敗したら例外。
        If Not (Win32Api.WTSEnumerateSessions(server, 01, buffer, count)) Then
            Throw New Win32Exception(Marshal.GetLastWin32Error())
        End If
        'バッファが空ならセッション無しと言うこと。
        If buffer.Equals(IntPtr.Zero) Then
            Return New WTSSessionInfo() {}
        End If
        Dim infos(count - 1As WTSSessionInfo
        'WTSSessionInfo構造体のサイズを取得。
        Dim size As Integer = Marshal.SizeOf(GetType(WTSSessionInfo))
        Try
            Dim i As Integer
            For i = 0 To count - 1
                'ポインタを、sizeずつずらしていく。
                Dim current As IntPtr = New IntPtr(buffer.ToInt64() + (size * i))
                'ポインタから構造体に変換して配列に格納。
                infos(i) = CType(Marshal.PtrToStructure(current,
                                         GetType(WTSSessionInfo)), WTSSessionInfo)
            Next
            Return infos
        Catch ex As Exception
            Throw New InvalidOperationException(
                            "バッファの読み出し中にエラーが発生しました。", ex)
            '確実に後始末
        Finally
            Win32Api.WTSFreeMemory(buffer)
        End Try
    End Function
    Public Shared Function GetProcessInfos(ByVal server As IntPtr) _
                                                             As WTSProcessInfo()
        'やってることはGetSessionInfosと同じ。使う関数と構造体が違うだけ。
        Dim buffer As IntPtr
        Dim count As Integer
        If Not (Win32Api.WTSEnumerateProcesses(server, 01, buffer, count)) Then
            Throw New Win32Exception(Marshal.GetLastWin32Error())
        End If
        If buffer.Equals(IntPtr.Zero) Then
            Return New WTSProcessInfo() {}
        End If
        Dim infos(count - 1As WTSProcessInfo
        Dim size As Integer = Marshal.SizeOf(GetType(WTSProcessInfo))
        Try
            Dim i As Integer
            For i = 0 To count - 1
                Dim current As IntPtr = New IntPtr(buffer.ToInt64() + (size * i))
                infos(i) = CType(Marshal.PtrToStructure(current,
                                         GetType(WTSProcessInfo)), WTSProcessInfo)
            Next
            Return infos
        Catch ex As Exception
            Throw New InvalidOperationException(
                            "バッファの読み出し中にエラーが発生しました。", ex)
        Finally
            Win32Api.WTSFreeMemory(buffer)
        End Try
    End Function
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)>
    Public Structure WTSSessionInfo
        Public SessionId As Integer
        Public WinStationName As String
        Public State As ConnectState
    End Structure
    Public Enum ConnectState
        Active = &H0
        Connected = &H1
        ConnectQuery = &H2
        Shadow = &H3
        Disconnected = &H4
        Idle = &H5
        Listen = &H6
        Reset = &H7
        Down = &H8
        Init = &H9
    End Enum
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)>
    Public Structure WTSProcessInfo
        Public SessionId As Integer
        Public ProcessId As Integer
        Public ProcessName As String
        Public UserSid As IntPtr
    End Structure
 
    Private NotInheritable Class Win32Api
        Declare Auto Function WTSOpenServer Lib "wtsapi32.dll" (
                ByVal name As StringAs IntPtr
        Declare Auto Function WTSEnumerateSessions Lib "wtsapi32.dll" (
                ByVal server As IntPtrByVal reserved As Integer,
                ByVal version As IntegerByRef infos As IntPtr,
                ByRef count As IntegerAs Boolean
        Declare Auto Function WTSEnumerateProcesses Lib "wtsapi32.dll" (
                ByVal server As IntPtrByVal reserved As Integer,
                ByVal version As IntegerByRef infos As IntPtr,
                ByRef count As IntegerAs Boolean
        Declare Auto Sub WTSFreeMemory Lib "wtsapi32.dll" (ByVal memory As IntPtr)
    End Class
End Class

で、これをこう使います。

Dim UserTokenHandle As IntPtr = IntPtr.Zero
TerminalService.GetProcessInfos(UserTokenHandle)
 
 
Dim infos As TerminalService.WTSSessionInfo() = TerminalService.GetSessionInfos(UserTokenHandle)
 
Dim activeID As UInteger
For Each inf As TerminalService.WTSSessionInfo In infos
    If inf.State = TerminalService.ConnectState.Active Then
        activeID = inf.SessionId
    End If
Next
WTSQueryUserToken(activeID, UserTokenHandle)
 
Dim ProcInfo As New PROCESS_INFORMATION
Dim StartInfo As New STARTUPINFOW
StartInfo.cb = CUInt(Runtime.InteropServices.Marshal.SizeOf(StartInfo))
Dim cmdline As New System.Text.StringBuilder
cmdline.Append("rundll32.exe user32.dll,LockWorkStation")
CreateProcessAsUser(UserTokenHandle, Nothing, cmdline, IntPtr.Zero, IntPtr.Zero, False0IntPtr.Zero, Nothing, StartInfo, ProcInfo)

これで 動作しました。

 

ちなみに、コマンドプロンプトから query session を実行すると、現在のセッションの状態を表示することができます。これを見て、セッションが少しわかったような気がしました。

VB.NET WindowsService から画面をロックする

ここしばらく、WindowsServiceからWindowsをシャットダウンするソフトを作っていましたが。

シャットダウンではなくて画面ロックでできないか、ということでやってみました。

 

 

<DllImport("Advapi32.dll", EntryPoint:="CreateProcessAsUser",
   ExactSpelling:=False, SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function CreateProcessAsUser(ByVal hToken As IntPtr,
                     ByVal lpApplicationName As String,
                     <[In](), Out(), [Optional]()> ByVal lpCommandLine As System.Text.StringBuilder,
                     ByVal lpProcessAttributes As IntPtr,
                     ByVal lpThreadAttributes As IntPtr,
                     <MarshalAs(UnmanagedType.Bool)> ByVal bInheritHandles As Boolean,
                     ByVal dwCreationFlags As Integer,
                     ByVal lpEnvironment As IntPtr,
                     ByVal lpCurrentDirectory As String,
                     <[In]()> ByRef lpStartupInfo As STARTUPINFOW,
<Out()> ByRef lpProcessInformation As PROCESS_INFORMATION) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("Wtsapi32.dll", EntryPoint:="WTSQueryUserToken", SetLastError:=True)>
Public Shared Function WTSQueryUserToken(ByVal SessionId As UInteger,
ByRef phToken As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function

<DllImport("kernel32.dll", EntryPoint:="WTSGetActiveConsoleSessionId", SetLastError:=True)>
Public Shared Function WTSGetActiveConsoleSessionId() As UInteger
End Function

 

<StructLayout(LayoutKind.Sequential)>
Public Structure STARTUPINFOW
  Public cb As UInteger
  <MarshalAs(UnmanagedType.LPWStr)>
  Public lpReserved As String
  <MarshalAs(UnmanagedType.LPWStr)>
  Public lpDesktop As String
  <MarshalAs(UnmanagedType.LPWStr)>
  Public lpTitle As String
  Public dwX As UInteger
  Public dwY As UInteger
  Public dwXSize As UInteger
  Public dwYSize As UInteger
  Public dwXCountChars As UInteger
  Public dwYCountChars As UInteger
  Public dwFillAttribute As UInteger
  Public dwFlags As UInteger
  Public wShowWindow As UShort
  Public cbReserved2 As UShort
  Public lpReserved2 As IntPtr
  Public hStdInput As IntPtr
  Public hStdOutput As IntPtr
  Public hStdError As IntPtr
End Structure

<StructLayout(LayoutKind.Sequential)>
Public Structure PROCESS_INFORMATION
  Public hProcess As IntPtr
  Public hThread As IntPtr
  Public dwProcessId As UInteger
  Public dwThreadId As UInteger
End Structure

 

ここまでが関数のインポート等です。

 

これを

 

Dim UserTokenHandle As IntPtr = IntPtr.Zero
WTSQueryUserToken(WTSGetActiveConsoleSessionId, UserTokenHandle)
Dim ProcInfo As New PROCESS_INFORMATION
Dim StartInfo As New STARTUPINFOW
StartInfo.cb = CUInt(Runtime.InteropServices.Marshal.SizeOf(StartInfo))
Dim cmdline As New System.Text.StringBuilder
cmdline.Append("rundll32.exe user32.dll,LockWorkStation")
CreateProcessAsUser(UserTokenHandle, Nothing, cmdline, IntPtr.Zero, IntPtr.Zero, False, 0, IntPtr.Zero, Nothing, StartInfo, ProcInfo)

 

のようにWindowsService上で呼び出すことにより、画面をロックすることができました。

 

実際やってみると、シャットダウンよりも安定して動作するようなので、今回はこちらを採用しようかと思っています。シャットダウンは、ふいに動作しないことがあったので、少し不安が残るのです。

 

Mistel BAROCCO の設定について2 MD200 を光らなくする

PN + 4 を 押すと 光らなくなります。 NUMLOCKは光ります。

 

MD600 のキーボードと接続して使用している場合は、色の設定もキーボードの方のマニュアルを参照しましょう。