Log into a website and submit form data? - linux

I was wondering if it's possible to log into name.com and update a specific domains DNS from SSH? The VPS hostname is the domain I want modified.
I basically want to update each DNS field with the following
Log into https://www.name.com/account/domain/details/$(hostname -i)#dns
A Record "" $(hostname -i)
A Record "*" $(hostname -i)
TXT default._domainkey cat /etc/opendkim/keys/"$(hostname)"/default.txt
TXT "" "v=spf1 mx a ip4:$(hostname -i) -all"
I know they have an API (have to request signup as a reseller) but that is not an option for me.

Related

Programatically set DNS servers (Windows, MacOS)

I need to programmatically set DNS servers of the host on their active network interfaces (Wi-fi, ethernet, etc) on both Windows, MacOS and as a bonus Linux.
I want to avoid having to manually update/pollute /etc/hosts for my Kubernetes services I am running on my ingress.
Currently, my process is to manually set the DNS server for each person in my team running our app
The problem with this is that it's a manual process, and I am having trouble trying to automate it because the outputs are weirdly formatted and hard to parse. This means I am unable to know which is the proper network interface to use.
Essentially, what needs to be done is the following (on both platforms)
Get the active networks name
Set the DNS servers for the active network to 127.0.0.1 & 8.8.4.4
What is being done manually currently
MacOS:
networksetup -setdnsservers Wi-Fi 127.0.0.1 8.8.8.8
sudo killall -HUP mDNSResponder
127.0.0.1 is the local DNS server running on node that serves the A record for the service
8.8.8.8 is Google's Public DNS Server
Currently, I am assuming the user on MacOS is using the "Wi-Fi" network, but i'd like to determine this programatically
Windows
As administrator:
netsh interface show interface
Locate the network connection for which you want the DNS server changed (eg: WiFi).
netsh interface ipv4 add dns "WiFi" 127.0.0.1 index=1
netsh interface ipv4 add dns "WiFi" 8.8.8.8 index=2
ipconfig /flushdns
On macOS, I don't think this will do what you want. When you configure multiple DNS servers on macOS, the system resolver doesn't try them in order, it just fires off requests semi-randomly between the available servers. This means it'll sometimes send off requests for your private servers to the public (Google) server, get told there's no such domain, and stop there. Or it'll send requests for pubic sites to the localhost DNS, and if that doesn't respond properly decide that site doesn't work. Basically, the macOS resolver doesn't do failover.
Are your private servers under a non-standard TLD or something like that? If so, you might be able to do the job by adding a file under /etc/resolver/ to redirect queries for that TLD to the private DNS server.
Anyway, in case it is useful, here's a way to detect the primary (active) network interface and set its DNS servers in macOS:
#!/bin/bash
interfaceDevice=$(netstat -rn | awk '($1 == "default") {print $6; exit}')
if [[ -z "$interfaceDevice" ]]; then
echo "Unable to get primary network interface device" >&2
exit 1
fi
interfaceName=$(networksetup -listallhardwareports | grep -B1 "Device: $interfaceDevice\$" | sed -n 's/^Hardware Port: //p')
if [[ -z "$interfaceName" ]]; then
echo "Unable to get primary network interface name" >&2
exit 1
fi
networksetup -setdnsservers "$interfaceName" 127.0.0.1 8.8.8.8

Can I resolve a MX record using hosts file?

To test mail server I need an MX record in DNS server, it always with a delay because DNS cache, I need to make it faster. Is there a way make an MX record locally like A record by etc/hosts file?
Thanks, this works.
echo "10.10.10.1 mail.example.com" | sudo tee --append /etc/hosts > /dev/null
echo "disable_dns_lookups = yes" | sudo tee --append /etc/postfix/main.cf > /dev/null
systemctl restart postfix
i'm managing to use postfix on a proxmox server to delivery the mail to a local mail server on a vm , with a different ip address from the dns mx record, i've found very useful this article,
http://www.readonlymaio.org/rom/2018/01/16/force-postfix-to-search-mx-records-in-etc-hosts-file/
he leds me to disable the dns lookup in postfix to force it to use the hosts A record !!
it works
in the hosts
X.X.X.X example.com
Edit the /etc/postfix/main.cf file and add this line:
disable_dns_lookups = yes
after, restart postfix

Write public ip to txt and upload to FTP automatically? (linux)

So I am looking for a way to upload a created Text File of sorts to a ftp
It needs to happen every lets say 4 hours
check ip
write ip to document or whatever
upload it to a FTP server with a spesific ipaddress, username and password
I am using Linux so a sh script will be fine
If you could explain what things go that'd be great
-(im still learning alot of stuff although being 5 years into use of Linux Mint and Fedora 21)
So far I have
dig +short myip.opendns.com #resolver1.opendns.com
This gets my public ip and next is to write it to a document and upload it to a ftp server which I do not know.
Just a final additional note, I'm looking for this to run every 4 hours by its self.
Quick and dirty first stab:
#!/bin/bash
# ftpmyip.sh
HOST=ftpserver
USER=userid
PASSWD=userpw
# write my ip address to file my_ip.txt
dig +short myip.opendns.com #resolver1.opendns.com > my_ip.txt
# ftp file to the ftp server
ftp -n $HOST <<SCRIPT
user $USER $PASSWD
binary
put my_ip.txt
quit
SCRIPT
Now, put it all in a cron job using crontab -e; line should say:
0 */4 * * * /home/enviousdata/ftpmyip.sh

Update all instances of IP address on a server

We currently have a dynamically provided IP address and are switching over to a static ip address. As such, I need to change the IP address on our 3 LAMP servers. These servers also run bind9 for DNS and postfix/dovecot for email. (MySQL is actually running as a Percona DB cluster which may be irrelevant.)
I think I have a good strategy, but want to check my logic with others who may have done this successfully before.
The concept is to stop all web, database, and mail services on each machine one at a time, pushing traffic to one of the two remaining servers, and run the following script to replace the old IP address with the new IP address, then reboot the server and attempt to push traffic back to it then proceed with the next server in the cluster if all goes well.
I used grep -r to find instances of the old ip address in the system and need to make sure that I'm not missing anything important that needs to be considered.
find /etc/bind -type f -print0 | xargs -0 sed -i 's/old.ip.address/new.ip.address/g'
find /etc/postfix -type f -print0 | xargs -0 sed -i 's/old.ip.address/new.ip.address/g'
find /etc/apache2 -type f -print0 | xargs -0 sed -i 's/old.ip.address/new.ip.address/g'
find /etc/postfix -type f -print0 | xargs -0 sed -i 's/old-ip-address/new-ip-address/g'
find /etc/bind -type f -print0 | xargs -0 sed -i 's/rev.address.ip.old/rev.address.ip.new/g'
As a point of clarification, grep -r found the IP address references in the /etc/bind/zones tables, the /etc/postfix configuration files, and the /etc/apache2 config file. The IP address separated by hyphens was also found in the postfix config files. The reverse IP address was also found in a /etc/bind/named.conf.local file and will also need to be replaced.
Can anyone see if I may be missing something here? I'm doing this in a production environment...not the most ideal of circumstances, of course.
Sorry all. Looks like I let this get stale after finding the solution. For posterity's sake, here's what seems to be working at this point:
$ORIGIN example.com.
$TTL 12H
; # symbol represents example.com.
# 12H IN SOA ns1.example.com. hostmaster#example.com. (
2015062954 ;serial
30M ;refresh
2M ;retry
2W ;expire
1D ;minimum TTL
)
NS ns1.example.com.
NS ns2.example.com.
MX 10 mail.example.com.
IN A 99.101.XXX.XXX
IN TXT "v=spf1 a mx ip4:99.101.XXX.XXX ~all"
IN SPF "v=spf1 a mx ip4:99.101.XXX.XXX -all"
ns1 IN A 99.101.XXX.XXX
ns2 IN A 99.101.XXX.XXX
mail IN A 99.101.XXX.XXX
IN TXT "v=spf1 a mx ip4:99.101.XXX.XXX ~all"
IN SPF "v=spf1 a mx ip4:99.101.XXX.XXX -all"
www IN A 99.101.XXX.XXX
dev IN A 99.101.XXX.XXX
demo IN A 99.101.XXX.XXX
webconf IN A 99.101.XXX.XXX
stats IN A 99.101.XXX.XXX
While the idea of using a find piped to an xargs sounds reasonable, I would take my 15 years of experience and tell you that is a bad idea. I would propose:
identify those services running on the boxes that are important (your find command works great here)
identify those files important to each of those services where address is defined
back up those files (cp to .orig works nicely)
create new files that contain your new addresses
This way you have a fast transition with:
cp somefile.new somefile
and a fast backout with:
cp somefile.orig somefile
Additionally, I would expect that the zones files contain actual DNS entries, so changing them is fine, but you'll probably need to reload named for those changes to take effect. Same goes for postfix, you'll want to postfix reload those as well.
EDIT (I haven't taken the time to actually load this zone, but it looks reasonably correct):
$ORIGIN example.com.
$TTL 12H # IN SOA ns1.example.com. hostmaster#example.com. (
2015062660 ;
30M ;refresh
2M ;retry
2W ;expire
1D ;minimum TTL
)
IN NS ns1.example.com.
IN NS ns2.example.com.
IN A 99.101.XXX.X
example.com. IN MX 10 mail.example.com.
mail IN A 99.101.XXX.X
IN TXT "v=spf1 a mx ip4:99.101.XXX.X ~all
ns1 IN A 99.101.XXX.X
ns2 IN A 99.101.XXX.X
www IN CNAME example.com.
dev IN CNAME example.com.
demo IN CNAME example.com.
webconf IN CNAME example.com.
stats IN CNAME example.com.
EDIT:
glue records

Get IPv4 and IPv6 with one command

I would like to know if it's possible to get IPv4 and IPv6 addresses with just one invocation of dig?
For example, this gives the IPv4 address:
dig hostname A
And this command will give me the IPv6 address:
dig hostname AAAA
How can I get both addresses, IPv4 and IPv6, with just one command?
It may be that this has been added to dig since the question was asked, but for completeness this can be accomplished through the following query:
dig hostname A hostname AAAA +short
Source: http://linux.die.net/man/1/dig -- under the 'Multiple Queries' section
If you're querying an authoritative server for the domain, you can get all the records for a name with an ANY query:
dig hostname ANY #servername
However, this won't work reliably if you're querying a caching server. When a caching server responds to an ANY query, it returns whatever records happen to be in cache at the time. If the name has both A and AAAA records, but the server has only looked up the A records recently, the AAAA records won't be in the cache, so it won't return them.
Furthermore, there is a proposal to allow DNS servers to refuse to answer ANY queries: Providing Minimal-Sized Responses to DNS Queries that have QTYPE=ANY. If you query a server that implements this, you may not be able to get both responses with a single query (although one of the suggestions in that draft is that an ANY query might just return all MX, A, and AAAA, since this is often what clients want). So for best reliability, you should just make two queries.
Now that IPv6 is a lot more common, I've found myself frequently needing to query both A and AAAA. I can never seem to remember the syntax, so I finally wrote a function for my ~/.bashrc called digall. I shared it with some friends and they loved it, so I threw it up on github in gist that anyone is welcome to use: https://gist.github.com/FreedomBen/23020c464779bb30cab754d92bdce6c6
Here's the current version which you can put in a file in your path and mark executable:
#!/usr/bin/env bash
#
# To use, simply run `digall <domain>` such as:
#
# digall example.com
# digall sub.example.com
#
# Place this file in your PATH. Suggest either /usr/local/bin/ or ~/bin
#
# Alternatively you can wrap it in a function called `digall` and put in ~/.bashrc
#
# License: MIT
declare -rx digall_color_restore='\033[0m'
declare -rx digall_color_red='\033[0;31m'
declare -rx digall_color_light_green='\033[1;32m'
declare -rx digall_color_light_blue='\033[1;34m'
declare -rx digall_color_light_cyan='\033[1;36m'
if [ -z "$1" ]; then
echo -e "${digall_color_red}Error: Please pass domain as first arg${digall_color_restore}"
else
echo -e "${digall_color_light_blue}Queries: (dig +noall +answer '$1' '<type>')...${digall_color_light_cyan}\n"
for t in SOA NS SPF TXT MX AAAA A; do
echo -e "${digall_color_light_green}Querying for $t records...${digall_color_restore}${digall_color_light_cyan}"
dig +noall +answer "$1" "${t}"
echo -e "${digall_color_restore}"
done
fi

Resources