MAL - Memória Auxiliar do Lutieri

Sábado, Dezembro 05, 2009

How find out which windows DC you logged in

So simple:

echo %LOGONSERVER%
or

systeminfo


To get a list os availble DC's in a specific domain:

nltest /dclist:domain.com



veriyfing that a domain controller can be located for a specific domain

nltest /dsgetdc:domain.com


More info:
How Domain Controllers Are Located in Windows

Marcadores: ,

Segunda-feira, Novembro 23, 2009

Descobrir SID de Grupos Windows

Caso você não consiga utilizar a sintaxe dominio\grupo com o ntlm-auth ou qualquer outro binário que utilize esse formato. É possível utilizar o SID do objeto.

# ntlm_auth --username=teste --password=senha --require-membership-of=domain\\gg_hr
[2009/11/23 14:45:31, 0] utils/ntlm_auth.c:get_require_membership_sid(236)
Could not parse domain\group into seperate domain/name parts!


# wbinfo -n gg_hr

S-1-5-21-2153899196-3371015479-2672548576-1129 Domain Group (2)

ou ADSI Edit do windows objectSID

Marcadores: ,

Quarta-feira, Novembro 11, 2009

some vbscript for Nagios checks

Detect if media is connected to a interface:



aStatusStr = Split("Disconnected,Connecting,Connected,Disconnecting," _
& "Hardware not present,Hardware disabled,Hardware malfunction," _
& "Media disconnected,Authenticating,Authentication succeeded," _
& "Authentication failed,Invalid address,Credentials required", ",")

strComputer = "."
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")

Set cItems = oWMI.ExecQuery("Select * from Win32_NetworkAdapter"_
& " where AdapterTypeID = 0") ' 0 = Ethernet 802.3

For Each oItem in cItems
''if Instr(oItem.NetConnectionID, "LAN") > 0 then

if oItem.NetConnectionID <> "" then

output = output & oItem.NetConnectionID & ": "_
& aStatusStr(oItem.NetConnectionStatus) & " * "

End if
''End if
Next

Wsh.echo output
WScript.Quit(0)
''' Source: http://msdn.microsoft.com/en-us/library/aa394216%28VS.85%29.aspx




Detect which node is the Active and Passive in a Windows Cluster environment:



set WshShell = CreateObject( "WScript.Shell" )

Set objNet = CreateObject("WScript.NetWork")

Dim strComputerName
strComputerName = objNet.ComputerName


sExe = "cluster resource ""cluster ip address"""
with CreateObject("WScript.Shell")
with .Exec(sExe)
with .StdOut
do until .AtEndofStream
s = s & Replace(.ReadLine, vbcr, "") _
& vbNewLine
Loop
end with ' StdOut
end with ' Exec
end with ' Shell

'wsh.echo s
Result = InStr(1, s, strComputerName, VBTEXTCOMPARE)


if Result <> 0 then
WScript.echo strComputerName & " is the ACTIVE"
Else
WScript.echo strComputerName & " is the PASSIVE"
end if

WScript.Quit(0)

Marcadores: ,

Quarta-feira, Novembro 04, 2009

Resizing physical disk and logical volumes

This is a VM which had the HD resized. Now it's time to resize the LVM partition, actually you don't do that, you will resize the PV.


sles11_php:~ # fdisk -l /dev/sda

Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0005035d

Device Boot Start End Blocks Id System
/dev/sda1 * 2 9 64260 83 Linux
/dev/sda2 10 74 522112+ 82 Linux swap / Solaris
/dev/sda3 75 1958 15133230 8e Linux LVM



Here you can see sda3 now with 15Gb

Now it's time to resize the PV



sles11_php:~ # pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name VGroot
PV Size 9.43 GB / not usable 263.50 KB
Allocatable yes
PE Size (KByte) 4096
Total PE 2414
Free PE 238
Allocated PE 2176
PV UUID LGgBQf-sw8J-fbnu-1EHL-0z1G-J31k-eAJoXc

sles11_php:~ # pvscan
PV /dev/sda3 VG VGroot lvm2 [9.43 GB / 952.00 MB free]
Total: 1 [9.43 GB] / in use: 1 [9.43 GB] / in no VG: 0 [0 ]

sles11_php:~ # pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

sles11_php:~ # pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name VGroot
PV Size 14.43 GB / not usable 2.36 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 3694
Free PE 1518
Allocated PE 2176
PV UUID LGgBQf-sw8J-fbnu-1EHL-0z1G-J31k-eAJoXc

sles11_php:~ #


sles11_php:~ # vgdisplay
--- Volume group ---
VG Name VGroot
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 8
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 6
Open LV 6
Max PV 0
Cur PV 1
Act PV 1
VG Size 14.43 GB
PE Size 4.00 MB
Total PE 3694
Alloc PE / Size 2176 / 8.50 GB
Free PE / Size 1518 / 5.93 GB
VG UUID CexmBK-uOq6-fnjo-qxFV-SIWW-04ZM-LENpdq


The VG didn't need any changes.



sles11_php:~ # lvresize -l +50%FREE /dev/VGroot/LVusr
Extending logical volume LVusr to 5.46 GB
Logical volume LVusr successfully resized



sles11_php:~ # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VGroot-LVroot
1014M 357M 658M 36% /
udev 248M 104K 247M 1% /dev
/dev/sda1 61M 16M 42M 28% /boot
/dev/mapper/VGroot-LVhome
1014M 4.3M 1010M 1% /home
/dev/mapper/VGroot-LVopt
1014M 60M 955M 6% /opt
/dev/mapper/VGroot-LVtmp
1014M 5.5M 1009M 1% /tmp
/dev/mapper/VGroot-LVusr
2.5G 2.4G 140M 95% /usr
/dev/mapper/VGroot-LVvar
2.0G 235M 1.8G 12% /var


sles11_php:~ # xfs_growfs /usr/
meta-data=/dev/mapper/VGroot-LVusr isize=256 agcount=4, agsize=163840 blks
= sectsz=512 attr=2
data = bsize=4096 blocks=655360, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=0
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 655360 to 1432576



sles11_php:~ # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VGroot-LVroot
1014M 357M 658M 36% /
udev 248M 104K 247M 1% /dev
/dev/sda1 61M 16M 42M 28% /boot
/dev/mapper/VGroot-LVhome
1014M 4.3M 1010M 1% /home
/dev/mapper/VGroot-LVopt
1014M 60M 955M 6% /opt
/dev/mapper/VGroot-LVtmp
1014M 5.5M 1009M 1% /tmp
/dev/mapper/VGroot-LVusr
5.5G 2.4G 3.2G 44% /usr
/dev/mapper/VGroot-LVvar
2.0G 235M 1.8G 12% /var



Here is a list of tools you need to extend each partition's type:

http://tldp.org/HOWTO/LVM-HOWTO/extendlv.html


An excellent howto in LVM:
http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/html_single/LVM-HOWTO.html


Resizing a ext3 partition with progress bar :)

e2fsck -f -C 0 /dev/xxx


If you forget the -C 0(zero) option you can send a SIGUSR1 signal to the process, like this:

kill -SIGUSR1 e2fsc_PID


Now it's time to actually resize:

resize2fs -p /dev/xxx

Marcadores:

Sexta-feira, Outubro 30, 2009

samba binding only a specifig interface

Tip: If your box has multiple NICs, you may not want Samba to broadcast its presence on both interfaces. To make it only use one IP add the following, in [global]:

interfaces = [interface_ip]/32 127.0.0.1/8
bind only interfaces = yes

Marcadores:

Quarta-feira, Outubro 28, 2009

Managing cached connections

I'm developing a script to failover different links when one of them fails. After some tests I could see some strange behavior. After changing the routing table, flushing the route cache, removing the NAT rule and creating a new one to satisfy the new link, the packets were going out through the new interface(specified in the new route) but using the translated IP address of the old NAT rule.

After some research I found out that linux kernel keeps a kind of cache for all connections, maybe just the NATed ones?!

The nice thing is you can see this table:

cat /proc/net/ip_conntrack

The netfilter team also developed a tool to manage this table, flush, list, delete, add entries, etc.
It's called conntrack-tools. It's a replacement for the /proc interface. What you will need is to compile and install the following:


libnfnetlink
libnetfilter_conntrack
conntrack-tools

You can download all the sources from:
http://conntrack-tools.netfilter.org/downloads.html

After installed you can call the conntrack binary.
I.e.:

conntrack -L -d x.x.x.x

The above command list all entries with x.x.x.x destination IP.

conntrack -F

The above command flushes the whole table. That's exactly what I have to do in order in my fail-over scripts.


conntrack -L -m 11

If you're using the MARK target in any iptables rule you can check out if the packets are being marked correctly with the above command. This command list all the connections with mark=11(-j MARK --set-mark 11)


References:

http://linux.derkeiler.com/Mailing-Lists/Debian/2005-08/3411.html
http://lists.netfilter.org/pipermail/netfilter-devel/2002-October/009530.html
http://mailman.ds9a.nl/pipermail/lartc/2003q1/007249.html
http://linux.die.net/man/8/conntrack
http://www.mail-archive.com/netfilter-devel@lists.samba.org/msg01394.html
http://conntrack-tools.netfilter.org/downloads.html

Marcadores:

Terça-feira, Outubro 27, 2009

customizing ls time output

ls -l --time-style="+%d-%m-%Y %H:%M:%S" /var/log/xxxxxxx


It's the same syntax used by date command

Marcadores:

Compilation stuff

./configure
....
checking lex library... -lfl
checking whether yytext is a pointer... yes
checking for bison... bison -y
checking for pkg-config... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for LIBNFNETLINK... no
configure: error: Cannot find libnfnetlink >= 1.0.0

However libnfnetlink was installed.

# ls /usr/local/lib/pkgconfig/
libnetfilter_conntrack.pc libnfnetlink.pc

# pkg-config --libs libnfnetlink
Package libnfnetlink was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnfnetlink.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnfnetlink' found


# PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ pkg-config --libs libnfnetlink
-L/usr/local/lib -lnfnetlink


Solution:
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ ./configure

Marcadores:



Chat with Lutieri G. B.

Subscribe in a reader