1

I´d like to connect my Ethernet2 with WIZ550 using DHCP but instead of Local IP, I want to use Hostname.

This is my code, it works. I get a Local IP Address and I can connect to Arduino using this IP, but I don't know how to setup hostname.

void setup() {

  // Monitor Serial begin
  Serial.begin(9600);
  Serial.println("Welcome to Itronic");

  // start the Ethernet connection:
#if defined(WIZ550io_WITH_MACADDRESS)
  if (Ethernet.begin() == 0) {
#else
  if (Ethernet.begin(mac) == 0) {
#endif
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for (;;)
      ;
  }
  // print your local IP address:
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }
  Serial.print("My MacAddress: ");
  for (byte thisByte = 0; thisByte < 6; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(mac[thisByte], HEX);
    Serial.print(",");
  }
  Serial.println();
  server.begin();
  // Hardware Serial (2,3) begin
  mySerial.begin(19200);
Serial.print("hostName: ");
  Serial.print(Ethernet.hostName());
      Serial.print("dnsDomainName: ");
  Serial.print(Ethernet.dnsDomainName());
  IRreceiver.enableIRIn();  // Start the receiver
}
  • You need a DNS server and your own domain name, or an entry in your hosts file (dependent on OS). Your router may provide the facilities if it's good enough. – Majenko Apr 24 '17 at 22:22
  • @Majenko, do you know any tutorial out there? – Marckaraujo Apr 24 '17 at 22:29
  • First off you really need to learn how the internet works. – Majenko Apr 24 '17 at 22:32
  • I am not a noob with code, I know how to put a apache server btw, however I dont know how to setup this for arduino, another thing is that I am trying to setup a local server, so I really think that your sugestion is wrong as I dont need a "real domain name" for local setup. – Marckaraujo Apr 24 '17 at 22:40
  • Ok, so you may be able to assign a hostname by allocating a static IP address and name to the MAC address in your DHCP server. If the DHCP server is integrated with your DNS server, as it is in some home routers, you may get auto-allocated a .local FQDN. If not you will have to either manually add the hostname to your DNS server, or if you only want to use it from the one computer then locate the "hosts" file (/etc/hosts on Linux, /private/etc/hosts on OS X and C:\Windows\System32\drivers\etc\hosts on Windows) and add the mapping. – Majenko Apr 24 '17 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.