FQDN from mono with dotnet on Linux - linux

If Powershell Core on Linux, using dotnet, can return the FQDN, then how does mono, also using dotnet, get the same result?
Here's powershell finding the local system FQDN:
thufir#dur:~/powershell$
thufir#dur:~/powershell$ pwsh
PowerShell v6.0.1
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /home/thufir/powershell>
PS /home/thufir/powershell> [System.Net.Dns]::GetHostByName((hostname)).HostName
dur.bounceme.net
PS /home/thufir/powershell>
and mono:
thufir#dur:~$
thufir#dur:~$ mono Projects/console/console/bin/Debug/console.exe
Hello Mono World
dur
dur
localhost
localhost
localhost
dur
done
thufir#dur:~$
code:
using System;
using System.Net;
using System.Net.Sockets;
using System.Globalization;
using System.Text;
namespace console
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine ("Hello Mono World");
String name;
name = Environment.MachineName;
Console.WriteLine(name);
name = System.Net.Dns.GetHostName();
Console.WriteLine(name);
name = System.Environment.GetEnvironmentVariable("COMPUTERNAME");
Console.WriteLine(name);
name =System.Net.Dns.GetHostEntry("localhost").HostName;
Console.WriteLine(name);
name = Dns.GetHostEntry("LocalHost").HostName;
Console.WriteLine(name);
// var ipProperties = IPGlobalProperties.GetIPGlobalProperties();
// name = string.Format("{0}.{1}", ipProperties.HostName, ipProperties.DomainName);
// Console.WriteLine(name);
name = Dns.GetHostEntry("LocalHost").HostName;
Console.WriteLine(name);
name = System.Net.Dns.GetHostEntry(Environment.MachineName).HostName;
Console.WriteLine(name);
Console.WriteLine("done");
}
}
}
thanks to jjw for pointing me in the right direction.
This is tantalizingly close, because dur, which is how the prompt is shown, is listed. Just not the whole name. Also:
thufir#dur:~$
thufir#dur:~$ hostname
dur
thufir#dur:~$
thufir#dur:~$ hostname --fqdn
dur.bounceme.net
thufir#dur:~$
thufir#dur:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 dur.bounceme.net dur
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
thufir#dur:~$
thufir#dur:~$ cat /etc/hostname
dur
thufir#dur:~$
Looking for the whole enchilada here, not just the prepend of dur but dur.bounceme.net if possible. Because Powershell Core can find the FQDN shouldn't mono be able to do the same?

Related

Qemu socket communication

I am trying to do a simple communication between a server (running on Ubuntu from Qemu with Cortex-A53 cpu) and a client (running on CentOS from my pc), using sockets.
If I run the C++ code only from Centos (both client.c and server.c) it works fine. Same if I run both from Ubuntu. But if I start the server.c from Ubuntu and client.c from CentOS the communication doesn't work.
The C code I'm using is from this tutorial:
https://www.geeksforgeeks.org/socket-programming-cc/
The Qemu command:
qemu-system-aarch64 -m 2048 -smp 2 -cpu cortex-a53 -M virt -nographic \
-pflash flash0.img \
-pflash flash1.img \
-drive if=none,file=${IMAGE},format=qcow2,id=hd0 -device virtio-blk-device,drive=hd0 \
-drive if=none,id=cloud,file=cloud.img,format=qcow2 \
-device virtio-blk-device,drive=cloud \
-device virtio-net-device,netdev=user0 \
-netdev user,id=user0,hostfwd=tcp::10022-:22 \
-device virtio-serial \
-chardev socket,id=foo,host=localhost,port=8080,server,nowait \
-device virtserialport,chardev=foo,name=test0
When I run server.c from Qemu and client.c from my pc. I see that the server.c it's blocked at accept() function and client.c it's blocked at read() function.
If I run the following command on Ubuntu:
$ sudo lsof -i -P -n | grep LISTEN I get this:
systemd-r 644 systemd-resolve 13u IPv4 15994 0t0 TCP 127.0.0.53:53 (LISTEN)
sshd 745 root 3u IPv4 18696 0t0 TCP *:22 (LISTEN)
sshd 745 root 4u IPv6 18699 0t0 TCP *:22 (LISTEN)
server 14164 root 3u IPv4 74481 0t0 TCP *:8080 (LISTEN)
If I run the same command on CentOS I get this:
qemu-syst 57073 ibestea 10u IPv4 2648807035 0t0 TCP 127.0.0.1:8080 (LISTEN)
qemu-syst 57073 ibestea 13u IPv4 2648807037 0t0 TCP *:10022 (LISTEN)
Any help is welcome.
The problem was that I was trying to connect to the socket from server part by using host address and port, but to access the Qemu data I had to connect to the socket using file descriptor /dev/vport3p1.
The server.c file should look something similar to this:
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
#include <sys/ioctl.h>
#define PORT 8080
#define DEV_PATH "/dev/vport3p1"
int main(int argc, char const *argv[])
{
int server_fd, new_socket, valread;
struct sockaddr_in address;
int opt = 1;
int addrlen = sizeof(address);
char buffer[1024] = {0};
char *hello = "Hello from server";
int dev_fd;
printf("SERVER: get an internet domain socket\n");
if ((dev_fd = open(DEV_PATH, O_RDWR)) == -1) {
perror("open");
exit(1);
}
else {
printf("SERVER: opened file descriptor first time = %d\n", dev_fd);
}
valread = read( dev_fd , buffer, 1024);
printf("%s\n",buffer );
valread = write(dev_fd , hello , strlen(hello));
printf("Hello message sent\n");
return 0;
}

DNS with BIND9 on Debian

I am trying to create my own dns using Bind9 and Debian 11
One Virtual Machine in Google Computing Engine has these configuration
Server 1 Google Cloud IP 35.206.115.212
The file /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
35.206.115.212 ns1.itinfrastructuretest.info ns1
10.128.0.2 instance-1.us-central1-a.c.dns-1902.internal instance-1 # Added by Google
169.254.169.254 metadata.google.internal # Added by Google
The file /etc/hostname
ns1
The File /etc/bind/zones/db.35.206.115
; BIND reverse data file for local loopback interface
;
$TTL 604800
# IN SOA itinfrastructuretest.info. root.itinfrastructuretest.info. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
IN NS ns1.itinfrastructuretest.info.
IN NS ns2.itinfrastructuretest.info.
1 IN PTR ns1.itinfrastructuretest.info.
2 IN PTR ns2.itinfrastructuretest.info.
3 IN PTR www.itinfrastructuretest.info.
The File /etc/bind/zones/db.itinfrastructuretest.info
$TTL 604800
# IN SOA ns1.itinfrastructuretest.info. root.itinfrastructuretest.info. (
5 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
; Name servers
itinfrastructuretest.info. IN NS ns1.itinfrastructuretest.info.
itinfrastructuretest.info. IN NS ns2.itinfrastructuretest.info.
; A records for name servers
ns1 IN A 35.206.115.212
ns2 IN A 15.236.156.144
; Other A records
# IN A 15.236.147.109
www IN A 15.236.147.109
IN TXT google-site-verification=EdC5AxyrHZ-HnRwyCgjckdIiFgFDzLniOyS2Tm6MwAk
; Mail server MX record
The File /etc/bind/named.conf.local
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone "itinfrastructuretest.info" {
type master;
file "/etc/bind/zones/db.itinfrastructuretest.info";
allow-transfer { 15.236.156.144; };
};
zone "115.206.35.in-addr.arpa" {
type master;
notify no;
file "/etc/bind/zones/db.35.206.115";
};
The File /etc/bind/named.conf.options
options {
directory "/var/cache/bind";
dnssec-validation auto;
listen-on-v6 { any; };
recursion no;
allow-transfer { none; };
auth-nxdomain no;
};
Server 2 Amazon Cloud IP 15.236.156.144
The Second Server on AWS
The /etc/hosts
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
127.0.1.1 ip-172-31-45-28.eu-west-3.compute.internal ip-172-31-45-28 ns2 ns2
127.0.0.1 localhost
15.236.156.144 ns2.itinfrastructuretest.info ns2
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
The file /etc/hostname
ns2
The File /etc/bind/named.conf.local
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone "itinfrastructuretest.info"{
type slave;
file "db.itinfrastructuretest.info";
masters { 35.206.115.212;};
};
zone "156.236.15.in-addr.arpa" {
type slave;
file "db.15.236.156";
masters {35.206.115.212 ;};
};
The File /etc/bind/named.conf.options
options {
directory "/var/cache/bind";
dnssec-validation auto;
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
allow-transfer { none; };
recursion no;
};
I was following these tutorials
How To Configure Bind as an Authoritative-Only DNS Server on Ubuntu 14.04
and
BIND9ServerHowto
The uploaded image shows that nothing was transferred from the master dns to the slave dns.
enter image description here
When I run dig command in the master dns server I got this
dig 35.206.115.212 115.206.35.in-addr.arpa. AXFR
; <<>> DiG 9.11.5-P4-5.1-Debian <<>> 35.206.115.212 115.206.35.in-addr.arpa. AXFR
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 39639
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;35.206.115.212. IN A
;; AUTHORITY SECTION:
. 86385 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2020051700 1800 900 604800 86400
;; Query time: 1 msec
;; SERVER: 169.254.169.254#53(169.254.169.254)
;; WHEN: Sun May 17 09:38:42 UTC 2020
;; MSG SIZE rcvd: 118
; Transfer failed.

firefox.NotConnectedException Unable to connect on port 7055 after 45000

When I tried to run selenium test using Xvfb i am getting this below error
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host localhost.localdomain on port 7055 after 45000 ms. Firefox console output:
Error: cannot open display: 1
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:113)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:128)
at com.gtech.automation.uk.webdriver.WebDriverFactory.getWebDriver(WebDriverFactory.java:41)
at com.gtech.automation.uk.dashboard.DashboardImpl.getWebDriver(DashboardImpl.java:53)
at com.gtech.automation.uk.dashboard.DashboardImpl.goHome(DashboardImpl.java:91)
at com.gtech.automation.uk.dashboard.steps.footer.ConnectionInfoSteps.isConnectionClosed(ConnectionInfoSteps.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at cucumber.runtime.Utils$1.call(Utils.java:34)
at cucumber.runtime.Timeout.timeout(Timeout.java:13)
at cucumber.runtime.Utils.invoke(Utils.java:30)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:35)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
at cucumber.runtime.Runtime.runStep(Runtime.java:298)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:48)
at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
These are the configuration i have used
Selenium version :2.53.0
Firefox version 46
I have checked the port 7055 its not active
netstat -ntlp | grep 7055
however Xvfb is running on the linux server
netstat -ntlp | grep Xvfb
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 31384/Xvfb
I tried running the Xvfb server with port number its not working
Xvfb :1 -screen 0 1024x768x16 -nolisten inet6 -port 7055 -from localhost.localdomain
Please help on this
Code
public static WebDriver getWebDriver(WebDriverImplementation implementation) {
switch (implementation) {
case FIREFOX:
return new FirefoxDriver(getFirefoxCapabilities());
case FIREBUG: {
FirefoxProfile firefoxProfile = new FirefoxProfile();
String seleniumPath = System.getProperty("selenuim.webdriver.path");
try {
firefoxProfile.addExtension(new File(seleniumPath + "/" + FIREBUG_FILENAME));
}catch (NullPointerException e)
{
logger.log(Level.SEVERE, null, e);
} catch(Exception e) {
System.out.println("Unexcepted Exception");
logger.log(Level.SEVERE, null, e);
}
firefoxProfile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION);
firefoxProfile.setPreference(seleniumPath, seleniumPath);
DesiredCapabilities capabilities = getFirefoxCapabilities();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
return new FirefoxDriver(capabilities);
}
case SHARED_FIREFOX:
return new SharedFireFoxDriver();
case MARIONETTE:
return new MarionetteDriver(getFirefoxCapabilities());
case INTERNET_EXPLORER:
return new InternetExplorerDriver();
default:
String message = "Unable to find a web driver implemention for : " + implementation.name();
logger.log(Level.SEVERE, message);
throw new UnsupportedOperationException(message);
}
}

Server can't find NXDOMAIN

I'm just tring to configure a DNS server in my local
I configure the /etc/named.conf
options {
listen-on port 53 {
127.0.0.1; 192.168.220.135;
};
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query {
localhost; 192.168.220.0/24;
};
allow-transfer{
localhost; 192.168.220.136;
};
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
also-notify {
};
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
zone "ayoub.local" IN {
type master;
file "direct.zone";
#allow-update {none;};
};
zone "220.168.192.in-addr.arpa" IN {
type master;
file "inverse.zone";
#allow-update {none;};};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
and /var/named/direct.zone
**$TTL 3H
# IN SOA MasterDNS.ayoub.local. root.ayoub.local. (
20160421 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minim
# IN NS MasterDNS.ayoub.local.
# IN NS SlaveDNS.ayoub.local.
# IN A 192.168.220.135
# IN A 192.168.220.136
# IN A 192.168.220.137
MasterDNS IN A 192.168.220.135
SlaveDNS IN A 192.168.220.136
Client IN A 192.168.220.137
and the /var/named/inverse.zone
$TTL 3H
# IN SOA MasterDNS.ayoub.local. root.ayoub.local. (
20160418 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
# IN NS MasterDNS.ayoub.local.
# IN NS SlaveDNS.ayoub.local.
# IN PTR ayoub.local.
MasterDNS IN A 192.168.220.135
SlaveDNS IN A 192.168.220.136
Client IN A 192.168.220.137
135 IN PTR MasterDNS.ayoub.local.
136 IN PTR SlaveDNS.ayoub.local.
137 IN PTR Client1.ayoub.local.
and the /etc/resolv.conf
domain ayoub.local
search ayoub.local
nameserver 127.0.0.1
nameserver 192.168.220.136
when i test the domaine with nslookup
;; Got SERVFAIL reply from 127.0.0.1, trying next server
;; connection timed out; trying next origin
;; Got SERVFAIL reply from 127.0.0.1, trying next server
;; connection timed out; no servers could be reached
and when i set /etc/resolv.conf with that
search localdomain
nameserver 192.168.220.2
i see comme result of nslookup
Server: 192.168.220.2
Address: 192.168.220.2#53
** server can't find ayoub.local: NXDOMAIN
Sometimes error happens due to nameserver 127.0.0.1
So in resolve.conf use following or any other name server you like.
Here is my resolve.conf file
nameserver 8.8.8.8
nameserver 1.1.1.1
I resolved the problem. I just forgot to change the group of direct. zone and inverse.zone from the root to named, command is :
chgroup named /var/named/direct.zone
and I force resolve to not changing by the DHCP :
chattr +i /etc/resolv.conf

Dovecot not working pop3 with postfix

telnet localhost pop3
Trying ::1...
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
netstat -l
tcp 0 0 *:www : LISTEN
tcp 0 0 localhost.localdoma:ipp : LISTEN
tcp 0 0 *:smtp : LISTEN
tcp 0 0 localhost.localdo:mysql : LISTEN
when i run this service dovecot start i got
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.553" (uid=1000 pid=26250 comm="start) interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply=0 destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init"))
on Dovecot.conf
protocols = imap imaps pop3 pop3s
disable_plaintext_auth = no
log_timestamp = "%Y-%m-%d %H:%M:%S "
mail_location = maildir:/var/spool/mail/%d/%n
mail_access_groups = mail
first_valid_uid = 106
first_valid_gid = 106
protocol imap {
}
protocol pop3 {
listen=*:110
pop3_uidl_format = %08Xu%08Xv
}
protocol lda {
postmaster_address = samer#aiu.com
mail_plugins = quota
log_path = /var/log/dovecot-deliver.log
info_log_path = /var/log/dovecot-deliver.log
}
auth default {
mechanisms = digest-md5 plain
passdb sql {
args = /etc/dovecot/dovecot-mysql.conf
}
userdb sql {
args = /etc/dovecot/dovecot-mysql.conf
}
user = root
}
If you get this message on the command line:
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.553" (uid=1000 pid=26250 comm="start) interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply=0 destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init"))
It indicates that you're not doing service dovecot restart as root. So make sure you do:
sudo service dovecot restart
The directive protocols = imap imaps pop3 pop3s should be sufficient to activate pop3 with dovecot. You can add
listen = *
to be sure dovecot will listen on all available interfaces. You can verify this by netstat -apn | grep 110. Are there any failures while starting dovecot? Can you post the dovecot related logs?
By default, dovecot logs to syslog, you can explicitly specify the log files:
# Log file to use for error messages, instead of sending them to syslog.
# /dev/stderr can be used to log into stderr.
log_path = /var/log/dovecot.log
# Log file to use for informational and debug messages.
# Default is the same as log_path.
info_log_path = /var/log/dovecot.info.log

Resources