Thursday, February 8, 2018

domain name system - Query between two DNS servers



I’ve been struggling with understanding DNS with BIND9.



I’ve used two machines, A and B, connected by a LAN and not for global use.



A is running a name server managing “example” domain and web server named “www”.



B is running a name server managing “sub.example” domain as subdomain with delegation from A and web server named “www” too.




Configuration files are bellow.



"named.conf" for "example" at machine A.



options {
directory "C:\dns\etc";
recursion yes;
version "XXX DNS Server 1.0X";

};

logging {
channel my_file {
file "c:\dns\etc\named.run" versions 5 size 1m;
severity debug 0;
print-category yes;
print-severity yes;
print-time yes;
};
category default {my_file;};
category queries {my_file;};

category lame-servers {my_file;};
category config {my_file;};
};


zone "." {
type hint;
file "named.root";
};


zone "localhost" {
type master;
file "localhost/fwd";
allow-update { none; };

};
zone "0.0.127.in-addr.arpa" {
type master;
file "localhost/rev";
allow-update { none; };

};
zone "example" {
type master;
file "example/fwd";
allow-update { none; };

};
zone "72.11.16.172.in-addr.arpa" {
type master;
file "example/rev";

allow-update { none; };
};


"zone file" for "example" at machine A.



$TTL 1H
@ 1H IN SOA example. postmaster.example. (
200508291 ; Serial
15M ; Refresh

5M ; Retry
1D ; Expire
15M) ; TTL

IN NS ns.example.
IN A 172.16.11.72
ns IN A 172.16.11.72
www IN A 172.16.11.72

sub IN NS ns.sub.example.

ns.sub.example. IN A 172.16.10.37


"named.conf" for "example" at machine B.



options {
directory "C:\dns\etc";
recursion yes;
version "unknown";
allow-transfer {172.16.11.72; };


};
logging {
channel my_file {
file "c:\dns\etc\named.run" versions 5 size 1m;
severity debug 0;
print-category yes;
print-severity yes;
print-time yes;
};

category default {my_file;};
category queries {my_file;};
category lame-servers {my_file;};
category config {my_file;};
};



zone "." {
type hint;

file "named.root";
};

zone "localhost" {
type master;
file "localhost/fwd";
allow-update { none; };

};
zone "0.0.127.in-addr.arpa" {

type master;
file "localhost/rev";
allow-update { none; };
};
zone "sub.example" {
type master;
file "example/fwd";
allow-update { none; };
};
zone "37.10.16.172.in-addr.arpa" {

type master;
file "example/rev";
allow-update { none; };
};
zone "example" {
type forward;
forward only;
forwarders {
172.16.11.72;
};

};


"zone file" for "sub.example" at machine B.



$TTL 1H
@ 1H IN SOA sub.example. postmaster.sub.example. (
200508291 ; Serial
15M ; Refresh
5M ; Retry

1D ; Expire
15M) ; TTL

IN NS ns.sub.example.
IN A 172.16.10.37
ns IN A 172.16.10.37
www IN A 172.16.10.37


Now I have four servers in two machines like below.




"ns.example"  and "www.example"   in machine A.

"ns.sub.example" and "www.sub.example" in machine B.


I can resolve “www.example” from A and “www.sub.example” from B.



But I can’t resolve “www.sub.example” from A and “www.example” from B.




The messages dig command shows and being written in BIND's log are the bottom.



Both A and B are respond "SERVFAIL" or "connection timed out; no servers could be reached" but there are no error message in BIND's log.



Actually they are Windows2008 servers and I’ve changed windows firewall filter to accept UPD 53 port each other.



Strangely there are no DROP message, even ALLOW message too, in firewall log both A and B.



I mean if I dig "www.example" from A I can see ALLOW message but if I dig "www.sub.exaple" I can’t see ALLOW and DROP message.




I think I have to classify this problem into BIND caused or Windows firewall caused.



What do I have to do first?



For example, I guess DNS query can't be sent to another machine of name server. That's why dig showed message "no servers could be reached".



How can I check DNS query is sent or NOT and why if it’s not sent?



dig at machine A.




C:\dns\bin>dig www.sub.example

; <<>> DiG 9.9.2-P1 <<>> www.sub.example
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 1777
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096

;; QUESTION SECTION:
;www.sub.example. IN A

;; Query time: 0 msec
;; SERVER: 172.16.11.72#53(172.16.11.72)
;; WHEN: Wed Mar 13 08:42:04 2013
;; MSG SIZE rcvd: 44

C:\dns\bin>dig @172.16.10.37 www.sub.example. a


; <<>> DiG 9.9.2-P1 <<>> @172.16.10.37 www.sub.example. a
; (1 server found)
;; global options: +cmd
;; connection timed out; no servers could be reached


dig at machine B.



C:\dns\bin>dig www.example


; <<>> DiG 9.9.2-P1 <<>> www.example
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 39790
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096

;; QUESTION SECTION:

;www.example. IN A

;; Query time: 4015 msec
;; SERVER: 172.16.10.37#53(172.16.10.37)
;; WHEN: Wed Mar 13 09:40:31 2013
;; MSG SIZE rcvd: 40

C:\dns\bin>dig @172.16.11.72 www.example. a

; <<>> DiG 9.9.2-P1 <<>> @172.16.11.72 www.example

; (1 server found)
;; global options: +cmd
;; connection timed out; no servers could be reached


BIND's log at A.



13-Mar-2013 14:43:22.624 general: info: managed-keys-zone: loaded serial 0
13-Mar-2013 14:43:22.624 general: info: zone 72.11.16.172.in-addr.arpa/IN: loaded serial 200508291
13-Mar-2013 14:43:22.624 general: info: zone 0.0.127.in-addr.arpa/IN: loaded serial 200508291

13-Mar-2013 14:43:22.624 general: info: zone example/IN: loaded serial 200508291
13-Mar-2013 14:43:22.624 general: info: zone localhost/IN: loaded serial 200508291
13-Mar-2013 14:43:22.624 general: notice: all zones loaded
13-Mar-2013 14:43:22.624 general: notice: running
13-Mar-2013 14:43:22.624 notify: info: zone example/IN: sending notifies (serial 200508291)
13-Mar-2013 14:43:22.624 notify: info: zone 72.11.16.172.in-addr.arpa/IN: sending notifies (serial 200508291)
13-Mar-2013 14:44:34.515 queries: info: client 172.16.11.72#58221 (www.sub.example): query: www.sub.example IN A +E (172.16.11.72)
13-Mar-2013 14:44:39.515 queries: info: client 172.16.11.72#58221 (www.sub.example): query: www.sub.example IN A +E (172.16.11.72)
13-Mar-2013 14:44:44.515 queries: info: client 172.16.11.72#58221 (www.sub.example): query: www.sub.example IN A +E (172.16.11.72)



BIND's log at B



13-Mar-2013 14:38:27.281 general: info: managed-keys-zone: loaded serial 0
13-Mar-2013 14:38:27.281 general: info: zone 0.0.127.in-addr.arpa/IN: loaded serial 200508291
13-Mar-2013 14:38:27.281 general: info: zone 37.10.16.172.in-addr.arpa/IN: loaded serial 200508291
13-Mar-2013 14:38:27.281 general: info: zone sub.example/IN: loaded serial 200508291
13-Mar-2013 14:38:27.281 general: info: zone localhost/IN: loaded serial 200508291
13-Mar-2013 14:38:27.296 general: notice: all zones loaded
13-Mar-2013 14:38:27.296 general: notice: running

13-Mar-2013 14:38:27.296 notify: info: zone sub.example/IN: sending notifies (serial 200508291)
13-Mar-2013 14:38:27.296 notify: info: zone 37.10.16.172.in-addr.arpa/IN: sending notifies (serial 200508291)
13-Mar-2013 14:46:08.984 queries: info: client 172.16.10.37#58326 (www.sub.example): query: www.sub.example IN A +E (172.16.10.37)
13-Mar-2013 14:46:11.250 queries: info: client 172.16.10.37#58330 (www.example): query: www.example IN A +E (172.16.10.37)
13-Mar-2013 14:46:17.250 queries: info: client 172.16.10.37#58330 (www.example): query: www.example IN A +E (172.16.10.37)

Answer



There are a couple of things I can think to suggest.



The first is that the return code you are getting in the failed digs is SERVFAIL. There can be several reasons for that, but one that you want to rule out first is that something is preventing name queries between machines. I recognize that you say you have turned off the Windows firewall rule for port 53 UDP, but I would suggest you demonstrate (to yourself, at least) that Machine B can do a "dig @machine-a www.example. a" and get the answer you expect. Then check that Machine A can query the server at Machine B.




Apart from that, it would be very helpful to see your named.conf and any messages named is logging. Showing us named.conf would allow us to check that your zones are specified correctly (most of the RRs in your zone files are relative to the zone origin so it's important to see how the zone is loaded so we can see what the origin really is..) and will help us figure out if either of the machines, or both, are supposed to be performing recursion.



Please provide more information; it will make it much easier to determine what is going on.



EDIT:



The dig output you have provided certainly makes it sound like the servers are not receiving requests from other machines:



; <<>> DiG 9.9.2-P1 <<>> @172.16.10.37 www.sub.example. a

; (1 server found)
;; global options: +cmd
;; connection timed out; no servers could be reached


and



; <<>> DiG 9.9.2-P1 <<>> @172.16.11.72 www.example
; (1 server found)
;; global options: +cmd

;; connection timed out; no servers could be reached


that would seem significant, wouldn't you agree?


linux - Cannot install grub to RAID1 (md0)

I have a RAID1 array on my Ubuntu 12.04 LTS and my /sda HDD has been replaced several days ago. I use this commands to replace:



# go to superuser
sudo bash
# see RAID state
mdadm -Q -D /dev/md0

# State should be "clean, degraded"
# remove broken disk from RAID
mdadm /dev/md0 --fail /dev/sda1
mdadm /dev/md0 --remove /dev/sda1
# see partitions
fdisk -l
# shutdown computer
shutdown now
# physically replace old disk by new
# start system again

# see partitions
fdisk -l
# copy partitions from sdb to sda
sfdisk -d /dev/sdb | sfdisk /dev/sda
# recreate id for sda
sfdisk --change-id /dev/sda 1 fd
# add sda1 to RAID
mdadm /dev/md0 --add /dev/sda1
# see RAID state
mdadm -Q -D /dev/md0

# State should be "clean, degraded, recovering"
# to see status you can use
cat /proc/mdstat


This is the my mdadm output after sync:



/dev/md0:
Version : 0.90
Creation Time : Wed Feb 17 16:18:25 2010

Raid Level : raid1
Array Size : 470455360 (448.66 GiB 481.75 GB)
Used Dev Size : 470455360 (448.66 GiB 481.75 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Thu Nov 1 15:19:31 2012
State : clean

Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

UUID : 92e6ff4e:ed3ab4bf:fee5eb6c:d9b9cb11
Events : 0.11049560

Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1

1 8 17 1 active sync /dev/sdb1


After bebuilding completion "fdisk -l" says what I have not valid partition table /dev/md0.
This is my fdisk -l output:



Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00057d19

Device Boot Start End Blocks Id System
/dev/sda1 * 63 940910984 470455461 fd Linux raid autodetect
/dev/sda2 940910985 976768064 17928540 5 Extended
/dev/sda5 940911048 976768064 17928508+ 82 Linux swap / Solaris

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors

Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000667ca

Device Boot Start End Blocks Id System
/dev/sdb1 * 63 940910984 470455461 fd Linux raid autodetect
/dev/sdb2 940910985 976768064 17928540 5 Extended
/dev/sdb5 940911048 976768064 17928508+ 82 Linux swap / Solaris


Disk /dev/md0: 481.7 GB, 481746288640 bytes
2 heads, 4 sectors/track, 117613840 cylinders, total 940910720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/md0 doesn't contain a valid partition table



This is my grub install output:



root@answe:~# grub-install /dev/sda
/usr/sbin/grub-setup: warn: Attempting to install GRUB to a disk with multiple partition labels or both partition label and filesystem. This is not supported yet..
/usr/sbin/grub-setup: error: embedding is not possible, but this is required for cross-disk install.
root@answe:~# grub-install /dev/sdb
Installation finished. No error reported.


Some version information:




grub-install (GRUB) 1.99-21ubuntu3.4
3.2.0-32-generic #51-Ubuntu SMP Wed Sep 26 21:33:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux


So



1) "update-grub" find only /sda and /sdb Linux, not /md0



2) "dpkg-reconfigure grub-pc" says "GRUB failed to install the following devices /dev/md0"




I cannot load my system except from /sdb1 (and by hand, not automatically), and in DEGRADED mode...



Anybody can resolve this issue? I have big headache with this.



UPDATE: after wiping out new disk with zeroes, copying partitions with sfdisk update-grub say:



root@answe:~# grub-install /dev/sda
error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.

error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.
Installation finished. No error reported.


Now update-grub generate same errors:



root@answe:~# update-grub
error: found two disks with the index 2 for RAID md0.

error: found two disks with the index 2 for RAID md0.
Generating grub.cfg ...
error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.
Found linux image: /boot/vmlinuz-3.2.0-32-generic
Found initrd image: /boot/initrd.img-3.2.0-32-generic

...
error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.
Found memtest86+ image: /boot/memtest86+.bin
No volume groups found
error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.
Found Ubuntu 12.04.1 LTS (12.04) on /dev/sda1
Found Ubuntu 12.04.1 LTS (12.04) on /dev/sdb1
error: found two disks with the index 2 for RAID md0.

error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.
error: found two disks with the index 2 for RAID md0.
done

Tuesday, February 6, 2018

virtual machines - Allocated too much memory from VMware to windows MBR disk, how to remove

I'm a junior sysadmin and today, I have allocated too much memory to a disk on a windows server 2008 VM through vsphere.



In my srv2008 vm, I saw two disks of 2tb with the same letter (spanned layout)
I needed space so I went in vsphere and raised capacity for one of the two drives, without noticing that in windows, they were mbr.



Now, all the disk that are part of the spanned layout are "Healthy(at risk)", I assume because on one of them I went over 2TB limit for mbr.
It seems like I can't easily remove the memory I allocated on vsphere, and I can't make another disk and add memory to it to increase my disk D:/ space.
I'm running out of space very soon and I'm racing against the clock. This is the main file server, anyone has an idea what I could do?



I tought about just creating another disk, not part of that spanned layout however I don't have enough free space to transfer everything, and I assume a lot of stuff here have hard coded paths to some specific file and moving them else where would break everything




The storage is on a nimble storage array

reverse proxy - Forward ssh connections to docker container by hostname

I have gotten into a very specific situation and although there are other ways to do this, I've kinda gotten obsessed with this and would like to find out a way to do it exactly like this:




Background



Say I have a server running several services tucked away in isolated docker containers. Since most of those services are http, I'm using an nginx proxy to expose specific subdomains to each service. For example, a node server is running on a docker container with its port 80 bound to 127.0.0.1:8000 on the host. I'll create a vhost in nginx that proxies all requests to myapp.mydomain.com to http://127.0.0.1:8000. That way, the docker container cannot be accessed from outside, except through myapp.mydomain.com.



Now I want to start a gogs docker container in such a way that gogs.mydomain.com points to the gogs container. So I start this gogs container with port 8000 bound to 127.0.0.1:8001 on the host. And an nginx site proxying requests to gogs.mydomain.com to http://127.0.0.1:8001 and it works well...



However, gogs being a git container, I would also like to access the repos like through git@gogs.mydomain.com:org/repo but that doesn't work with the current setup. One way to make that work would be to bind the port 22 of the container to the port 0.0.0.0:8022 on the host, and then the git ssh url can be something like git@gogs.mydomain.com:8022/repo.



(That doesn't seem to work; when I push to an origin with uri like that, git demands the password for user git on gogs.mydomain.com - instead of gogs.mydomain.com:8022 - but that's probably something I'm doing wrong and out of scope for this question, however, I would appreciate any diagnosis for that too)




Problem



My main concern is, that I want the ssh port :22 to be proxied just like I am proxying http ports using nginx; i.e. any ssh connections to gogs.mydomain.com get passed on to the container's port 22. Now I can't bind the container's ssh port to the host's ssh port because there is already an sshd running on the host. Also, that would mean that any connections to *.mydomain.com get passed to the container's sshd.






I want any ssh connections to:





  • mydomain.com host.mydomain.com or mydomain's IP address to be accepted and forwarded to the sshd on the host

  • gogs.mydomain.com or git.mydomain.com to be accepted an passed on to the sshd on the gogs container

  • *.mydomain.com (where * is anything other than the possibilities above) to be rejected



If it were http, I could easily make that work through nginx. Is there a way to do that for ssh?






(Also would like to go out on a limb and ask: is there a way to accomplish that with any tcp service in general?)




Any insights into the way I'm trying to do it here, are also welcome. I don't mind being told when what I'm trying to do is utterly stupid.






What I've already got in my mind:



Maybe I could share the sshd socket on host with the container as a ro volume? That would mean the sshd inside the container could pick up all connections to *.mydomain.com. Could there be a way to make the sshd inside the container reject all connections other than gogs.mydomain.com or git.mydomain.com? However, the sshd on the host will pick up all the connections to *.mydomain.com anyway including gogs.mydomain.com; so there would be a conflict. I dunno, I haven't actually tried it. Should I try it?

linux - iptables with non_transparent squid proxy

iptables has been working well with squid transparent. but with squid authentication method, its has some problems.

due to documents i found that, because suid in authentication mode, is destiation for packets, cannot set rules with iptables for actual destination/source.



is this right? has any solution?



if dosnt right, can you give me some squid config file with AD integration SSo, or any other authentication method



excuse me for my bad english. Thank you.

Monday, February 5, 2018

openvpn - Tunnel only one program (UDP & TCP) through another server

I have a windows machine at home and a server with debian installed.
I want to tunnel the UDP traffic from one (any only this) program on my windows machine through my server.



For tcp traffic this was easy using putty as a socks5 proxy and then connecting via ssh to my server - but this does not seem to work for UDP.

Then I setup dante as a socks5 proxy but it seems to create a new instance/thread per connection which leads to a huge ram usage for my server, so this was no option either.



So most people recommend openvpn, so my question: Can I use openvpn to just tunnel this one program through my server? Is there a way to maybe create a local socks5 proxy on my windows machine and set it as a proxy in my program and only this proxy then will use openvpn?



Thank you for your ideas

Sunday, February 4, 2018

Combining Apache ServerAlias and 301 Redirects



I've referenced this question but I'm not sure if I'm clear on how this works given this situation:




I have a client with two brands that are currently online like this:



Brand A (site 1)    Brand B (site 2)
--- ---
site 1 pages site 2 pages


Now, they've had a new site built that combines content from both sites and unifies their two brands into one:




Brand Unified (site 3)
---
site 3 pages


Clearly there are 301 redirects I want to put into place for each original site after I update the A records for each domain. However, the new site is a custom WordPress theme and WP only allows for one domain per installation. This leaves me with a situation where I can assign the original TLD from, say, Brand A as the site URL in WordPress, and then have the Brand B domain redirect to A.



I thought I would use a server block like this in the Apache site conf:





ServerName site1.com #site1.com now points directly here
ServerAlias site2.com #site2.com points directly but redirects
ServerAdmin admin@brandAsite.com
DocumentRoot /var/www/newsite


So, assuming there is nothing wrong with this configuration, what happens if I try to implement 301 redirects for site1 and site2 links? Specifically, since site2.com is now listed as an alias of site1.com, can I still effectively have 301 redirects in the .htaccess file in the /var/www/newsite/ directory or does ServerAlias interfere with that? I'm wondering if it gets aliased to back to site1.com and therefore the 301 rules wouldn't trigger?


Answer



If you are able to configure Apache conf, why complicate situation and put redirects (or anything) in .htaccess files? You seem to assign site2.com to /var/www/newsite only for the purpose to using .htaccess and nothing else. I would keep it simple, everything in one place:




NameVirtualHost  *:80

ServerName site1.com
DocumentRoot /var/www/newsite


ServerName site2.com

# Specifically mapped redirects
Redirect permanent /foo/ http://site1.com/new-foo/


# Root redirect (if no other cases above match)
Redirect permanent / http://site1.com/


linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...